pico
created pr with
100.1
cmds
checkout latest patchset:
ssh pr.pico.sh print 100 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 100.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 100
Patchset
100.1
fix(pipe): use ticker timer instead of sleep
Eric Bower
2025-12-26T04:45:05ZThe time.Sleep in the default case blocks for 5 seconds, during which context cancellation is ignored. If the session ends, the goroutine won't notice until the sleep completes.
Semantic diff summary
0 added,
1 modified,
0 signature changed,
0 removed
across 1 analyzed file
+19
-19
pkg/apps/pipe/cli.go
#
| ... | ... | @@ -52,25 +52,6 @@ func Middleware(handler *CliHandler) pssh.SSHServerMiddleware { | |
| 52 | 52 | ||
| 53 | 53 | pipeCtx, cancel := context.WithCancel(ctx) | |
| 54 | 54 | ||
| 55 | - | go func() { | |
| 56 | - | defer cancel() | |
| 57 | - | ||
| 58 | - | for { | |
| 59 | - | select { | |
| 60 | - | case <-pipeCtx.Done(): | |
| 61 | - | return | |
| 62 | - | default: | |
| 63 | - | _, err := sesh.SendRequest("ping@pico.sh", false, nil) | |
| 64 | - | if err != nil { | |
| 65 | - | logger.Error("error sending ping", "err", err) | |
| 66 | - | return | |
| 67 | - | } | |
| 68 | - | ||
| 69 | - | time.Sleep(5 * time.Second) | |
| 70 | - | } | |
| 71 | - | } | |
| 72 | - | }() | |
| 73 | - | ||
| 74 | 55 | cliCmd := &CliCmd{ | |
| 75 | 56 | sesh: sesh, | |
| 76 | 57 | args: args, |
| ... | ... | @@ -118,6 +99,25 @@ func Middleware(handler *CliHandler) pssh.SSHServerMiddleware { | |
| 118 | 99 | sesh.RemoteAddr().String(), | |
| 119 | 100 | ) | |
| 120 | 101 | ||
| 102 | + | defer cancel() | |
| 103 | + | go func() { | |
| 104 | + | ticker := time.NewTicker(5 * time.Second) | |
| 105 | + | defer ticker.Stop() | |
| 106 | + | ||
| 107 | + | for { | |
| 108 | + | select { | |
| 109 | + | case <-pipeCtx.Done(): | |
| 110 | + | return | |
| 111 | + | case <-ticker.C: | |
| 112 | + | _, err := sesh.SendRequest("ping@pico.sh", false, nil) | |
| 113 | + | if err != nil { | |
| 114 | + | logger.Error("error sending ping", "err", err) | |
| 115 | + | return | |
| 116 | + | } | |
| 117 | + | } | |
| 118 | + | } | |
| 119 | + | }() | |
| 120 | + | ||
| 121 | 121 | switch cmd { | |
| 122 | 122 | case "pub": | |
| 123 | 123 | err := handler.pub(cliCmd, topic, clientID) |