-
-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor handling of ProxyStreams and Client-Server Locks #3368
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lihaoyi
changed the title
Tweak Mill client-server locking protocol
Improve handling of ProxyStreams
Aug 14, 2024
lihaoyi
changed the title
Improve handling of ProxyStreams
Refactor handling of ProxyStreams
Aug 14, 2024
lihaoyi
changed the title
Refactor handling of ProxyStreams
Refactor handling of ProxyStreams and Client-Server Locks
Aug 14, 2024
lefou
approved these changes
Aug 14, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. We need to search our issues, I think this PR might close one.
This was referenced Aug 14, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR reduces the number of filesystem locks from 3 to 2, removes a potential race condition, fixes an edge case, tries harder to ensure all cleanup steps are run, consolidates and adds docs and fuzz tests to the
ProxyStream
logic, and reduces the Mill client fixed overhead by ~60ms on my laptopCombined
ProxyStreamPumper
andProxyOutputStream
into a singleProxyStream.java
file with two static inner classesProxyStream.Pumper
andProxyStream.Output
. This should help keep the related logic in one place, so it can easily be reviewed and read together in one place.Moved the magic
1
and-1
literals into constantsProxyStream.OUT
andProxyStream.ERR
Introduced a new
ProxyStream.END = 0
constant to the protocol, used viaProxyStream.sendEnd
, that can be used to terminate theProxyStream.Pumper
gracefully.Add some docs and simple fuzz tests for
ProxyStream
logic, asserting that both separate contents ofOUT
andERR
streams are round tripped unchanged, and also that the ordering of the combined out and err stream is preserved appropriately.ProxyStream
stream/socket is closed before theserverLock
is released, this results in the-1
"end of stream" being sent toProxyStream.Pumper
is mistaken for a length-1 packet being written to theERR
stream, causing the attempt to read the next byte to fail. We now properly disambiguate the-1
signalling end-of-stream (received as int-1
) from the-1
byte representing some data (received as int255
).Adjusted the
MillServerLauncher.run
termination logic; rather than waiting forserverLock
to be released to signal the server has completed and then waiting 50ms for data to finish streaming, we instead calloutPumperThread.join()
which waits for theProxyStream.Pumper
to terminate either via aProxyStream.END
packet or via the socket being closed.serverLock
but the logs take more than 50ms to arrive (e.g. due to CPU contention) resulting in logs being dropped.outPumperThread.join()
is now robust against both graceful shutdown (receiving0
) and non-graceful socket closing (receiving-1
), and either case should terminate the pumper after all readable input has been readThread.sleep(10)
after each command is processed, since we do not need to wait for the client to probe theserverLock
anymoreRemoved
serverLock
andWaitForSilence.java
since they are no longer usedMove a bunch of server-side termination logic into
finally
blocks: callingProxyStream.sendEnd
,sock.close()
,serverSocket.close()
, all live infinally
blocks to try to best-effort ensure they always run.Converted some
java.nio.file.*
callsites in the Scala code toos.*
for consistency with the rest of the Scala codeThis overall effect of this PR results in a hot
./mill resolve _
in the Mill repo dropping from ~435ms to ~375ms on my laptop, presumably due to the removals ofThread.sleep
s and various polling loopsPull request: #3368