Skip to content

Fix/app lifecycle shutdown drain - #170

Open
Qsnh wants to merge 2 commits into
mainfrom
fix/app-lifecycle-shutdown-drain
Open

Fix/app lifecycle shutdown drain#170
Qsnh wants to merge 2 commits into
mainfrom
fix/app-lifecycle-shutdown-drain

Conversation

@Qsnh

@Qsnh Qsnh commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Qsnh and others added 2 commits August 15, 2026 05:40
WeComConfig was missing its closing brace, so TelegramConfig was parsed
as part of its field list and internal/infra/config failed to compile:

  config.go:185:1: syntax error: unexpected keyword type,
  expected field name or embedded type

This broke `go build ./...` on main.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
App.Run cancelled the runner context and then closed the database without
waiting for any of the eight fire-and-forget goroutines. The feeder,
scheduler, dispatcher, reconciler and token-stats syncer all touch the
database on their way out of a cancelled loop, so shutdown raced against
db.Close.

Rebuild Run around errgroup, already the concurrency idiom used elsewhere
in this repo. `defer a.db.Close()` is declared before g.Wait(), so it
unwinds only after every runner has returned. A server error now cancels
the group and propagates out of Run, so `openbee server` exits non-zero
instead of logging and returning success.

Also folded in, all in the same shutdown path:

- Build the platform sender map in one shot (buildSenders) instead of
  handing an empty map to the failure notifier and filling it afterwards.
- Move startup recovery out of BuildApp into App.run, so constructing an
  App no longer mutates the database.
- Extract the hidden os.Setenv("OPENBEE_URL") out of buildAllEngines into
  publishRPCBaseURL.
- Guard routes.Server.httpServer with a mutex; Run wrote it while
  Shutdown read it from another goroutine.
- Name each runner so exits are traceable in logs.

Tests drive App.run directly through an httpServer stub. Verified to fail
against the previous behaviour before being committed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant