fix: add graceful shutdown and start for rest namespace adapter#5325
fix: add graceful shutdown and start for rest namespace adapter#5325jackye1995 merged 8 commits intolance-format:mainfrom
Conversation
1d9bab5 to
24e1454
Compare
|
Added some logging and found the issue: Basically the server of last test was still active, thus the new server fails to start and the client still calls into the old server. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
westonpace
left a comment
There was a problem hiding this comment.
Some minor suggestions but seems fine otherwise
| if let Some(server_handle) = adapter.server_handle.take() { | ||
| server_handle.abort(); | ||
| server_handle.shutdown(); | ||
| std::thread::sleep(std::time::Duration::from_millis(100)); |
There was a problem hiding this comment.
Can we add a comment about why this sleep is needed?
|
|
||
| // Use a random port to avoid conflicts | ||
| port = 4000 + new Random().nextInt(10000); | ||
| port = 10000 + new Random().nextInt(10000); |
There was a problem hiding this comment.
I suspect you already know but the canonical solution to this problem that I'm used to seeing is to use port number 0 and have that pass all the way down to the socket opening. Then the OS will assign a random ephemeral port and you can either return that from the constructor or make it available via an accessor.
Not sure if that is easily doable or possible but figured I'd mention it.
| /// Gracefully shut down the server. | ||
| /// | ||
| /// This signals the server to stop accepting new connections and wait for | ||
| /// existing connections to complete. |
There was a problem hiding this comment.
This method doesn't actually block until the shutdown is complete though right? I feel like we should document that fact (or ideally find some way to block?)
westonpace
left a comment
There was a problem hiding this comment.
Sweet. Thanks for doing the ephemeral port change!
…e-format#5325) Closes lance-format#5293 The test was flaky because the server in the last test is not properly shut down, and the one in new test fails to start and then client talks to the server in the last test. Made the RestAdapter run non-blocking start instead of blocking serve, so that the python and java level can more gracefully handle start and shutdown.
Closes #5293
The test was flaky because the server in the last test is not properly shut down, and the one in new test fails to start and then client talks to the server in the last test.
Made the RestAdapter run non-blocking start instead of blocking serve, so that the python and java level can more gracefully handle start and shutdown.