Fix session context corrupted problem #349
Merged
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.
Fixes #[ISSUE NUMBER].
No related issue
Changes proposed in this pull request:
First of all, thank you to show nice sample. It was very helpful to build echo project.
But, I found a problem that session in container has shared struct "context".
It makes race condition and cause data error or concurrent map writes.
The first commit is POC of race condition error that never want it to happen.
If remove
time.Sleep(1 * time.Second)
in second goroutine, you may see also concurrent map writes sometimes.So, I fixed it to do not use context sharing and use it as parameter.
Now there is a restriction of using session to use echo.context makes can not use in service layer, but there is no reason to access session in business logic, so it it not problem of this structure.
Please comment if you have any question about it.