Describe the issue
Calls to client.NewWorker do not support cancellation (i.e. a context), so the application/goroutine will be blocked while this function is ran. When called in the main goroutine, this can cause the entire application to become unresponsive. Here's a couple of cases where the function call will either take a long time, or retry indefinitely:
- Server is completely unavailable
- Client is configured to use TLS but the server has it disabled
Environment
- SDK: Go v0.79.43
- Engine: self-hosted v0.79.43
Expected behavior
Callers should be able to cancel this long-running function call.
Code to Reproduce, Logs, or Screenshots
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"syscall"
hatchet "github.com/hatchet-dev/hatchet/sdks/go"
)
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()
if err := run(ctx); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run(ctx context.Context) error {
client, err := hatchet.NewClient()
if err != nil {
return fmt.Errorf("create Hatchet client: %w", err)
}
// This cannot be cancelled even when OS signals are received. Wrapping this in a goroutine isn't
// a great solution because the goroutine will leak and continue attempting connections until
// the process is killed.
worker, err := client.NewWorker("worker")
if err != nil {
return fmt.Errorf("create Hatchet worker: %w", err)
}
log.Println("connected to Hatchet")
return nil
}
Run the above with the HATCHET_CLIENT_TOKEN var set but a TLS/non-TLS server/client mismatch, or with the server entirely unavailable, and try to exit the program without forcibly killing the process.
Additional context
N/A
Describe the issue
Calls to
client.NewWorkerdo not support cancellation (i.e. a context), so the application/goroutine will be blocked while this function is ran. When called in the main goroutine, this can cause the entire application to become unresponsive. Here's a couple of cases where the function call will either take a long time, or retry indefinitely:Environment
Expected behavior
Callers should be able to cancel this long-running function call.
Code to Reproduce, Logs, or Screenshots
Run the above with the
HATCHET_CLIENT_TOKENvar set but a TLS/non-TLS server/client mismatch, or with the server entirely unavailable, and try to exit the program without forcibly killing the process.Additional context
N/A