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

internal/jsonrpc2: fix jsonrpc result no pending[id] blocking #155

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions internal/jsonrpc2/jsonrpc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,10 @@ func (c *Conn) Run(runCtx context.Context) error {
Error: msg.Error,
ID: msg.ID,
}
rchan <- response
close(rchan)
if rchan != nil {
rchan <- response
close(rchan)
}
default:
for _, h := range c.handlers {
h.Error(runCtx, fmt.Errorf("message not a call, notify or response, ignoring"))
Expand Down
26 changes: 26 additions & 0 deletions internal/jsonrpc2/jsonrpc2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ func TestHeaderCall(t *testing.T) {
}
}

func TestResultsNoPendingID(t *testing.T) {
ctx := context.Background()
result := `{"jsonrpc":"2.0","result":["test"],"id":1}`

aR, bW := io.Pipe()
bR, aW := io.Pipe()

stream := jsonrpc2.NewStream(aR, aW)
run(ctx, t, false, bR, bW)

ch := make(chan int)

go func() {
stream.Write(ctx, []byte(result))
stream.Write(ctx, []byte(result))

ch <- 0
}()

select {
case <-ch:
case <-time.After(time.Second * 1):
t.Fatalf("NoPendingID Blocking")
}
}

func prepare(ctx context.Context, t *testing.T, withHeaders bool) (*jsonrpc2.Conn, *jsonrpc2.Conn) {
aR, bW := io.Pipe()
bR, aW := io.Pipe()
Expand Down