IoT: maxReceiveCount ко всем ошибкам consumer, ждать Shutdown до deferred Close, не 500 после успешного create

This commit is contained in:
Repinoid
2026-10-11 08:48:29 +03:00
parent 93d47376b1
commit 4c1b9b7b9e
3 changed files with 30 additions and 2 deletions
+9
View File
@@ -131,6 +131,11 @@ func run() int {
var wg sync.WaitGroup
wg.Add(2)
// shutdownDone — закрывается после завершения server.Shutdown (дренаж
// in-flight HTTP-запросов). run() ждёт его перед выходом, чтобы deferred
// Close (iotStore/devices) не сработали, пока запросы ещё дренируются.
shutdownDone := make(chan struct{})
// fatal — подсистема (bridge/consumer) завершилась с ПОСТОЯННОЙ ошибкой.
// Тогда после штатной остановки выходим с кодом ≠ 0, чтобы платформа
// перезапустила контейнер (ревью 🔴5: раньше процесс оставался жив, а
@@ -175,6 +180,7 @@ func run() int {
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer shutdownCancel()
_ = server.Shutdown(shutdownCtx)
close(shutdownDone)
}()
log.Info("iot-service listening", "addr", server.Addr)
@@ -182,9 +188,12 @@ func run() int {
log.Error("http server", "err", err)
cancel() // останавливаем bridge/consumer
waitWithTimeout(&wg, shutdownGrace)
<-shutdownDone
return 1
}
// Ждём завершения Shutdown (дренаж in-flight HTTP) до deferred Close.
<-shutdownDone
if !waitWithTimeout(&wg, shutdownGrace) {
log.Warn("iot-service: подсистемы не завершились за отведённое время", "grace", shutdownGrace)
}