8000 Prevent RPC blocking when context cancelled by MattBrittan · Pull Request #260 · eclipse-paho/paho.golang · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Prevent RPC blocking when context cancelled #260

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

Merged
merged 1 commit into from
Jul 29, 2024
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
11 changes: 8 additions & 3 deletions paho/extensions/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (h *Handler) getCorrelIDChan(cID string) chan *paho.Publish {

func (h *Handler) Request(ctx context.Context, pb *paho.Publish) (*paho.Publish, error) {
cID := fmt.Sprintf("%d", time.Now().UnixNano())
rChan := make(chan *paho.Publish)
rChan := make(chan *paho.Publish, 1) // Buffered to prevent goroutine leak when context cancelled

h.addCorrelID(cID, rChan)

Expand All @@ -95,8 +95,13 @@ func (h *Handler) Request(ctx context.Context, pb *paho.Publish) (*paho.Publish,
return nil, err
}

resp := <-rChan
return resp, nil
select {
case resp := <-rChan:
return resp, nil
case <-ctx.Done():
return nil, ctx.Err()
}

}

func (h *Handler) responseHandler(pb *paho.Publish) {
Expand Down
0