Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit675fc65

Browse files
spikecurtiskylecarbs
authored andcommitted
feat: make it harder to skip graceful shutdown accidentally (#1327)
* feat: make it harder to skip graceful shutdown accidentallySigned-off-by: Spike Curtis <spike@coder.com>* fixup: don't use unbuffered signal channelSigned-off-by: Spike Curtis <spike@coder.com>
1 parent15fadb1 commit675fc65

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

‎cli/server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ func server() *cobra.Command {
342342
returnxerrors.Errorf("notify systemd: %w",err)
343343
}
344344

345+
// Because the graceful shutdown includes cleaning up workspaces in dev mode, we're
346+
// going to make it harder to accidentally skip the graceful shutdown by hitting ctrl+c
347+
// two or more times. So the stopChan is unlimited in size and we don't call
348+
// signal.Stop() until graceful shutdown finished--this means we swallow additional
349+
// SIGINT after the first. To get out of a graceful shutdown, the user can send SIGQUIT
350+
// with ctrl+\ or SIGTERM with `kill`.
345351
stopChan:=make(chan os.Signal,1)
346352
defersignal.Stop(stopChan)
347353
signal.Notify(stopChan,os.Interrupt)
@@ -358,12 +364,13 @@ func server() *cobra.Command {
358364
returnerr
359365
case<-stopChan:
360366
}
361-
signal.Stop(stopChan)
362367
_,err=daemon.SdNotify(false,daemon.SdNotifyStopping)
363368
iferr!=nil {
364369
returnxerrors.Errorf("notify systemd: %w",err)
365370
}
366-
_,_=fmt.Fprintln(cmd.OutOrStdout(),"\n\n"+cliui.Styles.Bold.Render("Interrupt caught. Gracefully exiting..."))
371+
_,_=fmt.Fprintln(cmd.OutOrStdout(),"\n\n"+
372+
cliui.Styles.Bold.Render(
373+
"Interrupt caught, gracefully exiting. Use ctrl+\\ to force quit"))
367374

368375
ifdev {
369376
organizations,err:=client.OrganizationsByUser(cmd.Context(),codersdk.Me)

‎cli/server_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ func TestServer(t *testing.T) {
271271
require.NoError(t,err)
272272
err=currentProcess.Signal(os.Interrupt)
273273
require.NoError(t,err)
274+
// Send a two more signal, which should be ignored. Send 2 because the channel has a buffer
275+
// of 1 and we want to make sure that nothing strange happens if we exceed the buffer.
276+
err=currentProcess.Signal(os.Interrupt)
277+
require.NoError(t,err)
278+
err=currentProcess.Signal(os.Interrupt)
279+
require.NoError(t,err)
274280
<-done
275281
})
276282
t.Run("DatadogTracerNoLeak",func(t*testing.T) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp