The Close() method simply closes the done channel:
func(w*deploymentLogWriter)Close(){close(w.done)}
But it doesn't wait for the runFlushLoop goroutine to complete its final doFlush(). This means:
The caller of Close() may proceed to read deployment.Logs before the final flush writes to the database
If the build completes very quickly, the last batch of logs may be lost
There's a race between the final doFlush() accessing w.deployment and the caller potentially cleaning up
Suggested Fix
Use a sync.WaitGroup or a done-acknowledgment channel:
typedeploymentLogWriterstruct{// ...existing fields...flushedchanstruct{}}func(w*deploymentLogWriter)Close(){close(w.done)<-w.flushed// wait for final flush}func(w*deploymentLogWriter)runFlushLoop(){deferclose(w.flushed)// ...existing loop...}
## Bug
**File:** `internal/service/deploy/deploy.go`, `deploymentLogWriter`
**Severity:** MEDIUM — Data loss / race condition
### Description
The `Close()` method simply closes the `done` channel:
```go
func (w *deploymentLogWriter) Close() {
close(w.done)
}
```
But it doesn't wait for the `runFlushLoop` goroutine to complete its final `doFlush()`. This means:
1. The caller of `Close()` may proceed to read `deployment.Logs` before the final flush writes to the database
2. If the build completes very quickly, the last batch of logs may be lost
3. There's a race between the final `doFlush()` accessing `w.deployment` and the caller potentially cleaning up
### Suggested Fix
Use a `sync.WaitGroup` or a done-acknowledgment channel:
```go
type deploymentLogWriter struct {
// ...existing fields...
flushed chan struct{}
}
func (w *deploymentLogWriter) Close() {
close(w.done)
<-w.flushed // wait for final flush
}
func (w *deploymentLogWriter) runFlushLoop() {
defer close(w.flushed)
// ...existing loop...
}
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Bug
File:
internal/service/deploy/deploy.go,deploymentLogWriterSeverity: MEDIUM — Data loss / race condition
Description
The
Close()method simply closes thedonechannel:But it doesn't wait for the
runFlushLoopgoroutine to complete its finaldoFlush(). This means:Close()may proceed to readdeployment.Logsbefore the final flush writes to the databasedoFlush()accessingw.deploymentand the caller potentially cleaning upSuggested Fix
Use a
sync.WaitGroupor a done-acknowledgment channel:fixed in #9