puppetlabs-toy-chest / wash

Wide Area SHell: a cloud-native shell for bringing remote infrastructure to your terminal.
https://puppetlabs.github.io/wash
Apache License 2.0
180 stars 29 forks source link

Avoid shutdown race when handlers are slow, ensure GCP pubsub cancels #747

Closed MikaelSmith closed 4 years ago

MikaelSmith commented 4 years ago

Use a single select so if the context is canceled while we're waiting for a new GCP pubsub message, the read errors rather than remaining blocked.

When Shutdown is called on a net/http Server, it causes the Serve function to return but may still have further cleanup to do. The previous implementation sent a signal that shutdown was complete once Serve returned, which would cancel a timeout context. If the server was still actually cleaning up, we might get an error from Shutdown because the context it was using was canceled.

Close the stopped channel once Shutdown returns to trigger cleanup.

Fixes #711.