Remove struct field inboundCall.audioOut and mirror existing transfer workflow. - #808
Open
alexfish8 wants to merge 1 commit into
Open
Remove struct field inboundCall.audioOut and mirror existing transfer workflow.#808alexfish8 wants to merge 1 commit into
alexfish8 wants to merge 1 commit into
Conversation
alexfish8
force-pushed
the
afish/remove-field
branch
from
August 21, 2026 21:38
9403081 to
d186ef8
Compare
Comment on lines
1746
to
1754
| defer func() { | ||
| if retErr != nil && !c.done.Load() { | ||
| c.lkRoom.WriteOutboundAudioTo(c.audioOut) | ||
| c.lkRoom.WriteOutboundAudioTo(oldRoomAudioOut) | ||
| } else { | ||
| if err := oldRoomAudioOut.Close(); err != nil { | ||
| c.log().Warnw("failed to close old audio output", err) | ||
| } | ||
| } | ||
| }() |
There was a problem hiding this comment.
🟡 Dial-tone sink closed before its writer goroutine stops
On a successful transfer, deferred cleanup closes oldRoomAudioOut before the deferred rcancel() runs, because defers execute LIFO and rcancel is registered first. The tones.Play goroutine keeps writing samples to that writer until rctx is cancelled, so it writes to the writer during and after its close.
Prompt for agents
In inboundCall.transferCall (pkg/sip/inbound.go around lines 1737-1762), the dial-tone goroutine started with tones.Play(rctx, oldRoomAudioOut, ...) keeps writing audio samples to oldRoomAudioOut until rctx is cancelled. However, the deferred cleanup that calls oldRoomAudioOut.Close() is registered after 'defer rcancel()', so due to LIFO defer ordering the Close runs before rcancel() cancels the context. This means on the success path the writer is closed while the tones.Play goroutine may still be writing to it (write-after-close race). Ensure the tone goroutine is stopped (rctx cancelled) and ideally has finished before closing oldRoomAudioOut, e.g. by cancelling and waiting for the goroutine (a done channel or WaitGroup) prior to closing, or by registering the close defer so it runs strictly after the goroutine has exited.
Was this helpful? React with 👍 or 👎 to provide feedback.
alexlivekit
approved these changes
Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addressing Denys' comment on the refactor PR.