x264-go icon indicating copy to clipboard operation
x264-go copied to clipboard

Out of memory error agent: malloc.c:2379: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.

Open anand-dotworld opened this issue 2 years ago • 2 comments

I am creating a new encoder inside a function. I am not even calling the function just declaring the function. I am getting this error and program crashes and also all the go routines.

My current Implementation. I am just declaring I haven't even called the function anywhere. ` func (h *Handler) Encoder(ros_cameras []model.RosStreams, pc *webrtc.PeerConnection, disconnected chan bool) { for _, cam := range ros_cameras { videoTrack, err := webrtc.NewTrackLocalStaticSample( webrtc.RTPCodecCapability{ MimeType: webrtc.MimeTypeH264, }, fmt.Sprintf("video-%d", randutil.NewMathRandomGenerator().Uint32()), fmt.Sprintf("video-%d", randutil.NewMathRandomGenerator().Uint32()), ) if err != nil { panic(err) } _, err = pc.AddTrack(videoTrack) if err != nil { panic(err) }

	opts := &gen264.Options{
		Width:     640,
		Height:    480,
		FrameRate: 0,
		// Presets: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
		Preset: "zerolatency",
		// Tunings: film, animation, grain, stillimage, psnr, ssim, fastdecode, zerolatency.
		Tune: "veryfast",
		// Profiles: baseline, main, high, high10, high422, high444.
		Profile:  "baseline",
		LogLevel: gen264.LogError,
	}

	buffer := bytes.NewBuffer(make([]byte, 0))
	

	enc, err := gen264.NewEncoder(buffer, opts)
	if err != nil {
		fmt.Println("Error initializing codec", err)
		os.Exit(1)
	}
	fmt.Println(enc)

	// throttler := throttle.New(time.Millisecond * 50)
	sub, err := h.Subscribe(cam.TopicName, func(msg *sensor_msgs.Image) {
		

		defer func() {
			if r := recover(); r != nil {
				fmt.Println("Recovered in f", r)
			}
		}()

	})
	if err != nil {
		fmt.Println("Error in ros subscribe", err, sub)
	}

	go func() {
		<-disconnected
		fmt.Println("Stopping subscription")
		sub.Close()
	}()
}

}

`

This is the error. It goes on for more than 300 lines. I Also tweeked options and it doesn't fix it.

agent: malloc.c:2379: sysmalloc: Assertion (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed. SIGABRT: abort PC=0x7fd41cde303b m=13 sigcode=18446744073709551610 signal arrived during cgo execution

goroutine 40 [syscall]: runtime.cgocall(0xb82780, 0xc0004dfd40) /usr/local/go/src/runtime/cgocall.go:158 +0x5c fp=0xc0004df970 sp=0xc0004df938 pc=0x41175c github.com/pion/mediadevices/pkg/codec/x264._Cfunc_enc_new({0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x280, 0x1e0, 0x1, ...}, ...) _cgo_gotypes.go:420 +0x65 fp=0xc0004dfd40 sp=0xc0004df970 pc=0xb6c485 github.com/pion/mediadevices/pkg/codec/x264.newEncoder.func1(0x152a500?, 0x1?, 0x1?) /home/anand/Go/pkg/mod/github.com/pion/[email protected]/pkg/codec/x264/x264.go:85 +0x138 fp=0xc0004e0870 sp=0xc0004dfd40 pc=0xb6caf8 github.com/pion/mediadevices/pkg/codec/x264.newEncoder({0xfcac40, 0xc000414078}, {{0x0, 0x0}, {0x280, 0x1e0, 0x0, {0x0, 0x0}}, {0x0, ...}}, ...) /home/anand/Go/pkg/mod/github.com/pion/[email protected]/pkg/codec/x264/x264.go:85 +0x125 fp=0xc0004e0c80 sp=0xc0004e0870 pc=0xb6c845 github.com/pion/mediadevices/pkg/codec/x264.(*Params).BuildVideoEncoder(0x1e0?, {0xfcac40?, 0xc000414078?}, {{0x0, 0x0}, {0x280, 0x1e0, 0x0, {0x0, 0x0}}, ...}) /home/anand/Go/pkg/mod/github.com/pion/[email protected]/pkg/codec/x264/params.go:49 +0x6f fp=0xc0004e0d18 sp=0xc0004e0c80 pc=0xb6c0ef github.com/pion/mediadevices.(*CodecSelector).selectVideoCodecByNames(0xc000364d20, {0xfcac40, 0xc000414078}, {{0x0, 0x0}, {0x280, 0x1e0, 0x0, {0x0, 0x0}}, ...}, ...) /home/anand/Go/pkg/mod/github.com/pion/[email protected]/codec.go:74 +0x439 fp=0xc0004e0e60 sp=0xc0004e0d18 pc=0xb61dd9 github.com/pion/mediadevices.(*VideoTrack).newEncodedReader(0xc000012240, {0xc0004e1068, 0x1, 0x1}) /home/anand/Go/pkg/mod/github.com/pion/[email protected]/track.go:384 +0x165 fp=0xc0004e0ff0 sp=0xc0004e0e60 pc=0xb678e5 github.com/pion/mediadevices.(*VideoTrack).NewRTPReader(0xc000012240, {0xc0001c6bf6?, 0xc0000418c0?}, 0x8438ce24, 0x4b0) /home/anand/Go/pkg/mod/github.com/pion/[email protected]/track.go:419 +0x6a fp=0xc0004e1088 sp=0xc0004e0ff0 pc=0xb67d6a github.com/pion/mediadevices.(*baseTrack).bind(0xc000122840, {{0xc0000418c0, 0x20}, {{0x1602ac0, 0x0, 0x0}, {0xc00009a240, 0x1, 0x1}}, 0x8438ce24, ...}, ...) /home/anand/Go/pkg/mod/github.com/pion/[email protected]/track.go:173 +0x6f4 fp=0xc0004e1298 sp=0xc0004e1088 pc=0xb661f4 github.com/pion/mediadevices.(*VideoTrack).Bind(0x7fd3f5a91700?, {{0xc0000418c0, 0x20}, {{0x1602ac0, 0x0, 0x0}, {0xc00009a240, 0x1, 0x1}}, 0x8438ce24, ...}) /home/anand/Go/pkg/mod/github.com/pion/[email protected]/track.go:370 +0xc5 fp=0xc0004e1430 sp=0xc0004e1298 pc=0xb67625 github.com/pion/webrtc/v3.(*RTPSender).Send(0xc0000c1800, {{{0x1602ac0, 0x0, 0x0}, {0xc00009a240, 0x1, 0x1}}, {0xc00054e0c0, 0x1, 0x1}}) /home/anand/Go/pkg/mod/github.com/pion/webrtc/[email protected]/rtpsender.go:305 +0x515 fp=0xc0004e18b0 sp=0xc0004e1430 pc=0xb43bb5 github.com/pion/webrtc/v3.(*PeerConnection).startRTPSenders(0xe56200?, {0xc000196a20, 0xb, 0xc00052e280?}) /home/anand/Go/pkg/mod/github.com/pion/webrtc/[email protected]/peerconnection.go:1386 +0x1bd fp=0xc0004e1978 sp=0xc0004e18b0 pc=0xb3389d github.com/pion/webrtc/v3.(*PeerConnection).SetLocalDescription(0xc0003ba000, {0x3, {0xc000331800, 0x1764}, 0xc00040c240}) /home/anand/Go/pkg/mod/github.com/pion/webrtc/[email protected]/peerconnection.go:987 +0x38a fp=0xc0004e1a30 sp=0xc0004e1978 pc=0xb2f74a robotix-agent/handler.(*Handler).StartWebRtc(0xfca460?, {0xc0003dc000, 0xdbc4}) /home/anand/go/src/github.com/anand-dotworld/robotix-agent/handler/webrtc.go:262 +0x8cb fp=0xc0004e1ce0 sp=0xc0004e1a30 pc=0xb7e60b robotix-agent/handler.(*Handler).InitializeWebrtcSignalStream(0xc000132240, {0xfcfa20, 0xc000188000}) /home/anand/go/src/github.com/anand-dotworld/robotix-agent/handler/webrtc.go:77 +0x44b fp=0xc0004e1fb8 sp=0xc0004e1ce0 pc=0xb7dacb main.main.func4() /home/anand/go/src/github.com/anand-dotworld/robotix-agent/agent.go:54 +0x2e fp=0xc0004e1fe0 sp=0xc0004e1fb8 pc=0xb8164e runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0004e1fe8 sp=0xc0004e1fe0 pc=0x4742a1 created by main.main /home/anand/go/src/github.com/anand-dotworld/robotix-agent/agent.go:54 +0x377

goroutine 1 [chan receive]: runtime.gopark(0x0?, 0xc000235e50?, 0x3f?, 0xb0?, 0x0?) /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000086dd0 sp=0xc000086db0 pc=0x4461b6 runtime.chanrecv(0xc000196cc0, 0x0, 0x1) /usr/local/go/src/runtime/chan.go:583 +0x49b fp=0xc000086e60 sp=0xc000086dd0 pc=0x41475b runtime.chanrecv1(0xc000132240?, 0xfcfa20?) /usr/local/go/src/runtime/chan.go:442 +0x18 fp=0xc000086e88 sp=0xc000086e60 pc=0x414258 main.main() /home/anand/go/src/github.com/anand-dotworld/robotix-agent/agent.go:73 +0x43e fp=0xc000086f80 sp=0xc000086e88 pc=0xb813be runtime.main() /usr/local/go/src/runtime/proc.go:250 +0x212 fp=0xc000086fe0 sp=0xc000086f80 pc=0x445df2 runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000086fe8 sp=0xc000086fe0 pc=0x4742a1

goroutine 2 [force gc (idle)]: runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?) /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000072fb0 sp=0xc000072f90 pc=0x4461b6 runtime.goparkunlock(...) /usr/local/go/src/runtime/proc.go:369 runtime.forcegchelper() /usr/local/go/src/runtime/proc.go:302 +0xad fp=0xc000072fe0 sp=0xc000072fb0 pc=0x44604d runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000072fe8 sp=0xc000072fe0 pc=0x4742a1 created by runtime.init.6 /usr/local/go/src/runtime/proc.go:290 +0x25

goroutine 3 [GC sweep wait]: runtime.gopark(0x1?, 0x0?, 0x0?, 0x0?, 0x0?) /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000073790 sp=0xc000073770 pc=0x4461b6 runtime.goparkunlock(...) /usr/local/go/src/runtime/proc.go:369 runtime.bgsweep(0x0?) /usr/local/go/src/runtime/mgcsweep.go:297 +0xd7 fp=0xc0000737c8 sp=0xc000073790 pc=0x432897 runtime.gcenable.func1() /usr/local/go/src/runtime/mgc.go:178 +0x26 fp=0xc0000737e0 sp=0xc0000737c8 pc=0x427506 runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000737e8 sp=0xc0000737e0 pc=0x4742a1 created by runtime.gcenable /usr/local/go/src/runtime/mgc.go:178 +0x6b

goroutine 4 [GC scavenge wait]: runtime.gopark(0xc00003c150?, 0xfc3b30?, 0x0?, 0x0?, 0x0?) /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000073f70 sp=0xc000073f50 pc=0x4461b6 runtime.goparkunlock(...) /usr/local/go/src/runtime/proc.go:369 runtime.(*scavengerState).park(0x155bb00) /usr/local/go/src/runtime/mgcscavenge.go:389 +0x53 fp=0xc000073fa0 sp=0xc000073f70 pc=0x4308f3 runtime.bgscavenge(0x0?) /usr/local/go/src/runtime/mgcscavenge.go:622 +0x65 fp=0xc000073fc8 sp=0xc000073fa0 pc=0x430ee5 runtime.gcenable.func2() /usr/local/go/src/runtime/mgc.go:179 +0x26 fp=0xc000073fe0 sp=0xc000073fc8 pc=0x4274a6 runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000073fe8 sp=0xc000073fe0 pc=0x4742a1 created by runtime.gcenable /usr/local/go/src/runtime/mgc.go:179 +0xaa

goroutine 18 [finalizer wait]: runtime.gopark(0x155c440?, 0xc000007860?, 0x0?, 0x0?, 0xc000072770?) /usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000072628 sp=0xc000072608 pc=0x4461b6 runtime.goparkunlock(...) /usr/local/go/src/runtime/proc.go:369 runtime.runfinq() /usr/local/go/src/runtime/mfinal.go:180 +0x10f fp=0xc0000727e0 sp=0xc000072628 pc=0x42660f runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000727e8 sp=0xc0000727e0 pc=0x4742a1 created by runtime.createfing /usr/local/go/src/runtime/mfinal.go:157 +0x45

`

anand-dotworld avatar Aug 30 '22 07:08 anand-dotworld

Well, the crash is in github.com/pion/mediadevices/pkg/codec/x264._Cfunc_enc_new, I don't see anything related to this repo in the traceback. Probably can be because you are trying to initialize two different x264 encoders from two libraries at the same time, why not just use theirs? You can also try to build x264-go with extlib, I guess pion/mediadevices uses the external library, so at least they both use the same lib, but I doubt that is the only problem.

If you can write a small reproducible example with code from x264-go repo where it crashes I can maybe help you, but like it is now I have no other idea.

gen2brain avatar Aug 30 '22 07:08 gen2brain

Thank you for the earliest reply. Let me cross check with what you have said and also try to bring you with a better example if it doesn't work.

anand-dotworld avatar Aug 30 '22 07:08 anand-dotworld