Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soroban-rpc: fix datarace in bufferedResponseWriter.WriteOut #961

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions cmd/soroban-rpc/internal/network/requestdurationlimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,20 @@ func (w *bufferedResponseWriter) WriteOut(ctx context.Context, rw http.ResponseW
for k, v := range w.header {
headers[k] = v
}
complete := make(chan interface{})
go func() {
if len(w.buffer) == 0 {
if w.statusCode != 0 {
rw.WriteHeader(w.statusCode)
}
return
}

if len(w.buffer) == 0 {
if w.statusCode != 0 {
rw.WriteHeader(w.statusCode)
}
return
}
if w.statusCode != 0 {
rw.WriteHeader(w.statusCode)
}

if ctx.Err() == nil {
// the following return size/error won't help us much at this point. The request is already finalized.
rw.Write(w.buffer) //nolint:errcheck
close(complete)
}()
select {
case <-complete:
case <-ctx.Done():
}
}

Expand Down