You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
client.Close(): Properly terminate the session #4375
AFAIK client.Close() (all languages) shuts down the connection and that's it.
This means we're not properly shutting down the session and there are some side effects. For instance, there's a few pieces of code here and there doing a time.Sleep to make sure all logs are outputted to the terminal.
Proposal:
All SDKs: Properly shutdown the session on Close() (e.g. terminate the process?)
The stdin pipe technique is nice it handles the case where the parent process dies ungracefully. There is also a listener for sigint and sigterm that does the same thing as closing the stdin pipe though.
I'm not totally sure about python since a lot of the code has changed, but I think this gets handled by the exit stack here? cc @helderco to verify
I'm not sure yet, but one possible problem could be that the Go SDK doesn't actually wait for the process to shutdown fully, it just closes that pipe which then results in the child process to shutdown asynchronously. We could just change it to send SIGTERM and wait on the child proc to shutdown fully (w/ SIGKILL after some timeout). We'd want to leave in the stdin pipe approach to handle the unclean parent exit too, but SIGTERM should be the approach in the default happy path I think.
It's also possible there's problems elsewhere. E.g. maybe the remote engine hasn't flushed all the logs before the client session exits? Don't remember if buildkit handles that cleanly off the top of my head. But the SIGTERM fix is probably a good place to start w/ Go either way.
Activity
sipsma commentedon Jan 12, 2023
@aluzzardi Just for some more context: we should already be terminating the session child process when Close is called. The child process waits until its stdin pipe gets closed and then closes the localhost listener, which results in engine.Start exiting.
The stdin pipe technique is nice it handles the case where the parent process dies ungracefully. There is also a listener for sigint and sigterm that does the same thing as closing the stdin pipe though.
For each SDK:
I'm not sure yet, but one possible problem could be that the Go SDK doesn't actually wait for the process to shutdown fully, it just closes that pipe which then results in the child process to shutdown asynchronously. We could just change it to send SIGTERM and wait on the child proc to shutdown fully (w/ SIGKILL after some timeout). We'd want to leave in the stdin pipe approach to handle the unclean parent exit too, but SIGTERM should be the approach in the default happy path I think.
It's also possible there's problems elsewhere. E.g. maybe the remote engine hasn't flushed all the logs before the client session exits? Don't remember if buildkit handles that cleanly off the top of my head. But the SIGTERM fix is probably a good place to start w/ Go either way.
helderco commentedon Jan 12, 2023
Correct 👍
But we're not configuring timeout so it can be forcibly shutdown if it takes longer.