fix: make shutdown safe during active transfers#77
Conversation
📝 WalkthroughWalkthrough
ChangesGraceful Shutdown Fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
desktop/app.go (2)
199-213: 💤 Low valueInconsistent indentation inside
shutdownOnce.Doclosure.The closure body (lines 200-212) has inconsistent indentation which makes the code structure unclear.
♻️ Suggested formatting fix
func (a *App) shutdown(ctx context.Context) { a.shutdownOnce.Do(func() { - if a.serverApp != nil { - fmt.Println("🛑 Shutting down receiver server...") - if err := a.serverApp.Shutdown(); err != nil { - fmt.Println("⚠️ Server shutdown error:", err) + if a.serverApp != nil { + fmt.Println("🛑 Shutting down receiver server...") + if err := a.serverApp.Shutdown(); err != nil { + fmt.Println("⚠️ Server shutdown error:", err) + } } - } - if a.senderApp != nil { - fmt.Println("🛑 Shutting down sender server...") - if err := a.senderApp.Shutdown(); err != nil { - fmt.Println("⚠️ Sender shutdown error:", err) + if a.senderApp != nil { + fmt.Println("🛑 Shutting down sender server...") + if err := a.senderApp.Shutdown(); err != nil { + fmt.Println("⚠️ Sender shutdown error:", err) + } } - } close(a.eventsClosed) }) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@desktop/app.go` around lines 199 - 213, Fix the inconsistent indentation inside the shutdownOnce.Do closure in the app.go file. The if statements checking a.serverApp and a.senderApp, along with the close(a.eventsClosed) call, should all be aligned at the same indentation level within the closure body. Ensure all code within the anonymous function passed to shutdownOnce.Do follows consistent indentation rules so the block structure is clear.
160-179: 💤 Low valueInconsistent indentation obscures code structure.
Lines 166-174 and 175 appear to be at inconsistent indentation levels within the
caseblock. While functionally correct (Go uses braces, not indentation), this harms readability and could mislead future maintainers.♻️ Suggested formatting fix
func (a *App) processEvents() { for { select { case event, ok := <-a.eventChan: if !ok { return } - if event.Name == "device_connected" { - currentRealIP := getLocalIP() - if a.currentIP != "" && a.currentIP != currentRealIP { - fmt.Printf("🔄 IP Change Detected! Old: %s, New: %s\n", a.currentIP, currentRealIP) - a.currentIP = currentRealIP - newURL := fmt.Sprintf("%s://%s:%s", beamsync.ServerScheme(), a.currentIP, a.currentPort) - a.safeEmit("url_changed", newURL) + if event.Name == "device_connected" { + currentRealIP := getLocalIP() + if a.currentIP != "" && a.currentIP != currentRealIP { + fmt.Printf("🔄 IP Change Detected! Old: %s, New: %s\n", a.currentIP, currentRealIP) + a.currentIP = currentRealIP + newURL := fmt.Sprintf("%s://%s:%s", beamsync.ServerScheme(), a.currentIP, a.currentPort) + a.safeEmit("url_changed", newURL) + } } - } a.safeEmit(event.Name, event.Data) case <-a.eventsClosed: return } } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@desktop/app.go` around lines 160 - 179, The indentation within the case event, ok := <-a.eventChan block is inconsistent. The if event.Name == "device_connected" block (lines 168-174) and the subsequent a.safeEmit(event.Name, event.Data) call (line 175) are not properly aligned with the preceding if !ok check. Fix this by ensuring all statements within this case block are indented at the same level to reflect their common position within the select statement's case handler.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@desktop/app.go`:
- Around line 199-213: Fix the inconsistent indentation inside the
shutdownOnce.Do closure in the app.go file. The if statements checking
a.serverApp and a.senderApp, along with the close(a.eventsClosed) call, should
all be aligned at the same indentation level within the closure body. Ensure all
code within the anonymous function passed to shutdownOnce.Do follows consistent
indentation rules so the block structure is clear.
- Around line 160-179: The indentation within the case event, ok :=
<-a.eventChan block is inconsistent. The if event.Name == "device_connected"
block (lines 168-174) and the subsequent a.safeEmit(event.Name, event.Data) call
(line 175) are not properly aligned with the preceding if !ok check. Fix this by
ensuring all statements within this case block are indented at the same level to
reflect their common position within the select statement's case handler.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 086cdea7-2cab-479b-94b4-42401c790ce0
📒 Files selected for processing (3)
beamsync/server.gobeamsync/server_test.godesktop/app.go
Signed-off-by: Sonal Mittal <105050791+mittalsonal@users.noreply.github.com>
1446063 to
09eb6f4
Compare
Summary
eventChanwhile transfer callbacks may still enqueue eventsClose()to gracefulShutdown(ctx)with a forced-close fallbackFixes #47
Validation
git diff --checkgo test -run TestHTTPServerShutdownWaitsForActiveRequest -count=1 -vinbeamsync(passes with Go 1.25.5)go test ./...inbeamsyncreaches the existing suite but local Windows profile fails TLS config tests becauseC:\Users\Garima Varshney\.configexists as a file, preventingos.UserConfigDir()subdirectory creationgo test ./...indesktoprequires frontend assets first (frontend/distmissing locally), matching the CI order where frontend build runs before desktop Go tests