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

Goroutines of RTCPSender are never stopped #1206

Closed
1 of 13 tasks
gabridego opened this issue Oct 27, 2022 · 2 comments
Closed
1 of 13 tasks

Goroutines of RTCPSender are never stopped #1206

gabridego opened this issue Oct 27, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@gabridego
Copy link

gabridego commented Oct 27, 2022

Which version are you using?

v0.20.1

Which operating system are you using?

  • Linux amd64 standard
  • Linux amd64 Docker
  • Linux arm64 standard
  • Linux arm64 Docker
  • Linux arm7 standard
  • Linux arm7 Docker
  • Linux arm6 standard
  • Linux arm6 Docker
  • Windows amd64 standard
  • Windows amd64 Docker (WSL backend)
  • macOS amd64 standard
  • macOS amd64 Docker
  • Other (please describe)

Describe the issue

When a FFmpeg process publishing to the server is stopped and its clients are disconnected, the goroutines associated to the RTCPSender object keep running, leading to possible goroutine leaks:

goroutine 26 [select]:
github.com/aler9/gortsplib/pkg/rtcpsender.(*RTCPSender).run(0xc0000849c0)
	/home/user/go/pkg/mod/github.com/aler9/[email protected]/pkg/rtcpsender/rtcpsender.go:64 +0x132
created by github.com/aler9/gortsplib/pkg/rtcpsender.New
	/home/user/go/pkg/mod/github.com/aler9/[email protected]/pkg/rtcpsender/rtcpsender.go:45 +0x10a

To better identify the problem, we modified the run() function in our local installation of gortsplib/pkg/rtcpsender/rtcpsender.go like this:

func (rs *RTCPSender) run() {
	defer close(rs.done)

	t := time.NewTicker(rs.period)
	t_new := time.NewTicker(10 * time.Second)
	defer t.Stop()
	defer t_new.Stop()

	for {
		select {
		case <-t.C:
			report := rs.report(now())
			if report != nil {
				rs.writePacketRTCP(report)
			}

		case <-t_new.C:
			log.Println("===================", rs.packetCount, time.Now())

		case <-rs.terminate:
			log.Println("=================== TERMINATE", time.Now())
			return
		}
	}
}

Even after both publisher and client processes are killed, the first message is printed forever and the loop never reaches its termination.

Describe how to replicate the issue

  1. start the server
  2. publish any stream through FFmpeg: ffmpeg -re -stream_loop -1 -i out.mp4 -c copy -f rtsp rtsp://localhost:8554/mystream
  3. read with any player, such as FFplay: ffplay rtsp://localhost:8554/mystream
  4. kill player and publisher processes

Did you attach the server logs?

yes

2022/10/27 14:38:43 INF [RTSP] [conn 127.0.0.1:48020] opened
2022/10/27 14:38:43 INF [RTSP] [session 433090564] created by 127.0.0.1:48020
2022/10/27 14:38:43 INF [RTSP] [session 433090564] is publishing to path 'mystream', with UDP, 1 track (H264)
2022/10/27 14:38:53 INF [RTSP] [conn 127.0.0.1:41048] opened
2022/10/27 14:38:53 INF [RTSP] [session 676059982] created by 127.0.0.1:41048
2022/10/27 14:38:53 INF [RTSP] [session 676059982] is reading from path 'mystream', with UDP, 1 track (H264)
2022/10/27 14:39:03 =================== 358 2022-10-27 14:39:03.81869608 +0200 CEST m=+22.248182167
2022/10/27 14:39:13 =================== 716 2022-10-27 14:39:13.818089331 +0200 CEST m=+32.247575401
2022/10/27 14:39:21 INF [RTSP] [conn 127.0.0.1:41048] closed (EOF)
2022/10/27 14:39:23 =================== 1070 2022-10-27 14:39:23.817989394 +0200 CEST m=+42.247475480
2022/10/27 14:39:33 =================== 1428 2022-10-27 14:39:33.818080162 +0200 CEST m=+52.247566239
2022/10/27 14:39:36 INF [RTSP] [session 433090564] destroyed (teared down by 127.0.0.1:48020)
2022/10/27 14:39:36 INF [RTSP] [session 676059982] destroyed (terminated)
2022/10/27 14:39:36 INF [RTSP] [conn 127.0.0.1:48020] closed (EOF)
2022/10/27 14:39:43 =================== 1525 2022-10-27 14:39:43.823728934 +0200 CEST m=+62.253214995
2022/10/27 14:39:53 =================== 1525 2022-10-27 14:39:53.817958749 +0200 CEST m=+72.247444823
2022/10/27 14:40:03 =================== 1525 2022-10-27 14:40:03.821344118 +0200 CEST m=+82.250830192
2022/10/27 14:40:13 =================== 1525 2022-10-27 14:40:13.827152066 +0200 CEST m=+92.256638157
2022/10/27 14:40:23 =================== 1525 2022-10-27 14:40:23.823803003 +0200 CEST m=+102.253289080
2022/10/27 14:40:33 =================== 1525 2022-10-27 14:40:33.823804391 +0200 CEST m=+112.253290461

Last messages are repeated every 10 seconds.

Did you attach a network dump?

no

@aler9 aler9 added the bug Something isn't working label Oct 28, 2022
aler9 added a commit to bluenviron/gortsplib that referenced this issue Oct 28, 2022
(bluenviron/mediamtx#1206)

RTCPSender was not closed when its corresponding stream was closed
@aler9
Copy link
Member

aler9 commented Nov 3, 2022

Thanks for reporting the bug, it is fixed in v0.20.2.

@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2023

This issue is being locked automatically because it has been closed for more than 6 months.
Please open a new issue in case you encounter a similar problem.

@github-actions github-actions bot locked and limited conversation to collaborators May 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants