Skip to content

Commit 32ea43c

Browse files
authored
do not ack bye (#745)
* do not ack bye * fix ci
1 parent 947bb9f commit 32ea43c

6 files changed

Lines changed: 25 additions & 22 deletions

File tree

pkg/sip/inbound.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ func (c *sipInbound) sendBye(ctx context.Context, headers map[string]string) {
21412141
c.setCSeq(r)
21422142
c.swapSrcDst(r)
21432143
c.drop()
2144-
sendAndACK(ctx, c, r)
2144+
sendBye(ctx, c.log, c, r)
21452145
}
21462146

21472147
func (c *sipInbound) sendStatus(ctx context.Context, result Result, headers map[string]string) {

pkg/sip/outbound.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ func (c *sipOutbound) sendBye(ctx context.Context, headers map[string]string) {
11731173
}
11741174
c.setCSeq(r)
11751175
c.drop()
1176-
sendAndACK(ctx, c, r)
1176+
sendBye(ctx, c.log, c, r)
11771177
}
11781178

11791179
func (c *sipOutbound) sendCancel(ctx context.Context, headers map[string]string) {

pkg/sip/protocol.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"time"
2626

2727
"github.com/livekit/protocol/livekit"
28+
"github.com/livekit/protocol/logger"
2829
"github.com/livekit/psrpc"
2930
"github.com/livekit/sip/pkg/stats"
3031
"github.com/livekit/sipgo/sip"
@@ -225,18 +226,17 @@ func getContactURI(c *config.Config, ip netip.Addr, t Transport) URI {
225226
}
226227
}
227228

228-
func sendAndACK(ctx context.Context, c Signaling, req *sip.Request) {
229+
// sendBye sends a BYE and waits for its final response. BYE is a non-INVITE
230+
// transaction (RFC 3261 §17.1.2): the response ends it, no ACK is sent.
231+
func sendBye(ctx context.Context, log logger.Logger, c Signaling, req *sip.Request) {
229232
tx, err := c.Transaction(req)
230233
if err != nil {
234+
log.Infow("cannot send BYE", "error", err)
231235
return
232236
}
233237
defer tx.Terminate()
234-
r, err := sipResponse(ctx, tx, nil, nil)
235-
if err != nil {
236-
return
237-
}
238-
if r.StatusCode == 200 {
239-
_ = c.WriteRequest(sip.NewAckRequest(req, r, nil))
238+
if _, err := sipResponse(ctx, tx, nil, nil); err != nil {
239+
log.Infow("no response to BYE", "error", err)
240240
}
241241
}
242242

test/integration/docker_mac_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"github.com/ory/dockertest/v3"
1313
)
1414

15-
const dockerBridgeIP = "172.17.0.1"
16-
1715
var Docker *dockertest.Pool
1816

1917
func TestMain(m *testing.M) {

test/integration/docker_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"github.com/ory/dockertest/v3"
1212
)
1313

14-
const dockerBridgeIP = "172.17.0.1"
15-
1614
var Docker *dockertest.Pool
1715

1816
func TestMain(m *testing.M) {

test/integration/livekit_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package integration
33
import (
44
"context"
55
"fmt"
6-
"net"
76
"os"
87
"sync/atomic"
98
"testing"
@@ -22,7 +21,7 @@ var debugLKServer = os.Getenv("DEBUG_LK_SERVER") != ""
2221

2322
var redisLast uint32
2423

25-
func runRedis(t testing.TB) *redis.RedisConfig {
24+
func runRedis(t testing.TB, network *dockertest.Network) (*redis.RedisConfig, string) {
2625
name := fmt.Sprintf("siptest-redis-%d", atomic.AddUint32(&redisLast, 1))
2726
c, ok := Docker.ContainerByName(name)
2827
if ok {
@@ -33,6 +32,7 @@ func runRedis(t testing.TB) *redis.RedisConfig {
3332
&dockertest.RunOptions{
3433
Name: name,
3534
Repository: "redis", Tag: "latest",
35+
Networks: []*dockertest.Network{network},
3636
})
3737
if err != nil {
3838
t.Fatal(err)
@@ -44,7 +44,8 @@ func runRedis(t testing.TB) *redis.RedisConfig {
4444
waitTCPPort(t, addr)
4545

4646
t.Log("Redis running on", addr)
47-
return &redis.RedisConfig{Address: addr}
47+
// addr: host-published (SIP service); name:6379: in-network (LiveKit container).
48+
return &redis.RedisConfig{Address: addr}, name
4849
}
4950

5051
type LiveKit struct {
@@ -55,14 +56,21 @@ type LiveKit struct {
5556
var livekitLast uint32
5657

5758
func runLiveKit(t testing.TB) *LiveKit {
58-
redis := runRedis(t)
59+
id := atomic.AddUint32(&livekitLast, 1)
5960

60-
_, port, err := net.SplitHostPort(redis.Address)
61+
// Shared network so LiveKit reaches Redis by name, avoiding a
62+
// container->host round-trip that some CI runners block.
63+
network, err := Docker.CreateNetwork(fmt.Sprintf("siptest-net-%d", id))
6164
if err != nil {
6265
t.Fatal(err)
6366
}
67+
t.Cleanup(func() {
68+
_ = network.Close()
69+
})
70+
71+
redis, redisName := runRedis(t, network)
6472

65-
name := fmt.Sprintf("siptest-livekit-%d", atomic.AddUint32(&livekitLast, 1))
73+
name := fmt.Sprintf("siptest-livekit-%d", id)
6674
c, ok := Docker.ContainerByName(name)
6775
if ok {
6876
t.Log("Livekit-server container already exists - stopping and removing", name)
@@ -74,12 +82,11 @@ func runLiveKit(t testing.TB) *LiveKit {
7482
Repository: "livekit/livekit-server", Tag: "master",
7583
Cmd: []string{
7684
"--dev",
77-
// TODO: We use Docker bridge IP here instead of the host IP.
78-
// Maybe run on the host network instead? We might need it for RTP anyway.
79-
"--redis-host", dockerBridgeIP + ":" + port,
85+
"--redis-host", redisName + ":6379",
8086
"--bind", "0.0.0.0",
8187
},
8288
ExposedPorts: []string{"7880/tcp"},
89+
Networks: []*dockertest.Network{network},
8390
})
8491
if err != nil {
8592
t.Fatal(err)

0 commit comments

Comments
 (0)