Skip to content

Commit

Permalink
Fix socket timeout handling in PythonParser
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Oct 24, 2024
1 parent 2f1689a commit 90c5e00
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,13 @@ public Stream<SourceFile> parseInputs(Iterable<Input> inputs, @Nullable Path rel
generator.writeString("parse-python-file");
generator.writeString(input.getPath().toString());
}
}, parser -> {
int oldTimeout = socket.getSoTimeout();
try {
if (parseTimeoutMs > 0) {
// make sure we don't block forever
socket.setSoTimeout(parseTimeoutMs);
}
Tree tree = new ReceiverContext(remotingContext.newReceiver(parser), remotingContext).receiveTree(null);
return (SourceFile) tree;
} catch (Exception e) {
return ParseError.build(this, input, relativeTo, ctx, e);
} finally {
socket.setSoTimeout(oldTimeout);
// make sure we don't block forever when reading
if (parseTimeoutMs > 0) {
socket.setSoTimeout(parseTimeoutMs);
}
}, parser -> {
Tree tree = new ReceiverContext(remotingContext.newReceiver(parser), remotingContext).receiveTree(null);
return (SourceFile) tree;
}, socket)))
.withSourcePath(path)
.withFileAttributes(FileAttributes.fromPath(input.getPath()))
Expand Down

0 comments on commit 90c5e00

Please sign in to comment.