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

Added timeout channel for Client Send #3

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Changes from 1 commit
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
Next Next commit
Added timeout channel
JckHoe committed Nov 13, 2023
commit 35379556b293361740e0dcedaec29d5b2f92e640
10 changes: 9 additions & 1 deletion diameter.go
Original file line number Diff line number Diff line change
@@ -113,14 +113,22 @@ func (d *Diameter) Send(client *DiameterClient, msg *DiameterMessage) (uint32, e
hopByHopID := req.Header.HopByHopID
client.hopIds[hopByHopID] = make(chan *diam.Message)

// Timeout channel
timeoutChan := time.After(60 * time.Second)

// Send CCR
_, err := req.WriteTo(client.conn)
if err != nil {
return uint32(0), err
}

// Wait for CCA
resp := <-client.hopIds[hopByHopID]
var resp *diam.Message
select {
case resp = <-client.hopIds[hopByHopID]:
case <-timeoutChan:
return uint32(5012), errors.New("Response timeout")
}
//log.Infof("Received CCA \n%s", resp)

delete(client.hopIds, hopByHopID)