Don't use nosync for the standard log package. #657
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TL;DR; The standard library 'log' package uses locks around blocking IO calls which seems like an inappropriate use of the 'nosync' package. Not using 'nosync' for this package fixed a bug observed in one of my applications.
I've just encountered the following error in one of my apps:
My attempts to build a minimal reproduction case have thus far failed, but here's my speculation:
I'm not entirely sure what 'nosync's purpose is, but I guess it's a lighter-weight version of 'sync', to be used when there's no possibility of synchronization being an actual issue, due to JS's single-threaded nature.
The failure:
Corresponds to this transpiled code:
Which in turn corresponds to this code in the standard library:
If I understand GopherJS's scheduling adequately (also reinforced by my reading of the transpiled log function), it's quite possible for the
defer l.mu.Unlock()
execution to be significantly delayed in from the rest of the function, since there's aWrite()
call (on line 168), which triggers a blocking IO checkpoint, allowing other goroutines to be scheduled, leading to a possible race condition.