Skip to content

Commit 8f52101

Browse files
authored
Fix usage of psrpc request maps by reference for non-read-only uses (#634)
1 parent 916263f commit 8f52101

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

pkg/sip/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ func (c *Client) createSIPParticipant(ctx context.Context, req *rpc.InternalCrea
223223
"toUser", req.CallTo,
224224
)
225225

226+
req.ParticipantAttributes = maps.Clone(req.ParticipantAttributes) // shallow clone - string/string map. Needed to avoid mutating psrpc req
226227
state := NewCallState(c.getIOClient(req.ProjectId), c.createSIPCallInfo(req))
227228

228229
defer func() {
@@ -260,7 +261,7 @@ func (c *Client) createSIPParticipant(ctx context.Context, req *rpc.InternalCrea
260261
pass: req.Password,
261262
dtmf: req.Dtmf,
262263
dialtone: req.PlayDialtone,
263-
headers: req.Headers,
264+
headers: maps.Clone(req.Headers), // shallow clone - string/string map. Needed to avoid mutating psrpc req
264265
includeHeaders: req.IncludeHeaders,
265266
headersToAttrs: req.HeadersToAttributes,
266267
attrsToHeaders: req.AttributesToHeaders,

pkg/sip/service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"io"
2323
"log/slog"
24+
"maps"
2425
"net"
2526
"net/netip"
2627
"os"
@@ -359,7 +360,8 @@ func (s *Service) transferSIPParticipant(ctx context.Context, req *rpc.InternalT
359360
ctx, cdone := context.WithTimeout(context.WithoutCancel(ctx), timeout)
360361
defer cdone()
361362

362-
err := s.processParticipantTransfer(ctx, req.SipCallId, req.TransferTo, req.Headers, req.PlayDialtone)
363+
headers := maps.Clone(req.Headers) // shallow clone - string/string map. Needed to avoid mutating psrpc req
364+
err := s.processParticipantTransfer(ctx, req.SipCallId, req.TransferTo, headers, req.PlayDialtone)
363365
select {
364366
case pending.Done <- err:
365367
default:

0 commit comments

Comments
 (0)