-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
materialize-boilerplate: fix race condition in extended logger
Materializations can send acknowledgement messages concurrently with reading load or flush messages. This would show up occasionally as a panic due to concurrent access of variables in the "waiting for documents" part of the extendedLogger event handler. This adds a mutex to guard that concurrent access.
- Loading branch information
1 parent
c94068f
commit e2d6ba1
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package boilerplate | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func TestExtendedLoggerWaitingForDocsRace(t *testing.T) { | ||
// TODO(whb): If we ever start running our tests with the -race flag | ||
// enabled, this outer loop won't be necessary. As is, running the enclosed | ||
// sequence ~100 times or so will reliably produce a panic unless sufficient | ||
// synchronization is provided in the extended logger event handler. | ||
for idx := 0; idx < 100; idx++ { | ||
be := newBindingEvents() | ||
logger := newExtendedLogger(loggerAtLevel{lvl: log.InfoLevel}, be) | ||
handler := logger.handler() | ||
|
||
handler(sentStartedCommit) | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(2) | ||
go func() { | ||
for idx := 0; idx < 10; idx++ { | ||
handler(readLoad) | ||
} | ||
wg.Done() | ||
}() | ||
|
||
go func() { | ||
handler(sentAcknowledged) | ||
wg.Done() | ||
}() | ||
|
||
wg.Wait() | ||
} | ||
} |