node-datachannel icon indicating copy to clipboard operation
node-datachannel copied to clipboard

SegFault after IceState::Failed

Open ibsusu opened this issue 2 months ago • 1 comments

I'm not entirely sure if I should create this issue here or at libdatachannel I'm using "version": "0.8.0-dev" which in the CMakeLists.txt contains:

FetchContent_Declare(
    libdatachannel
    GIT_REPOSITORY https://github.com/paullouisageneau/libdatachannel.git
    GIT_TAG "v0.20.2"
)

peerconnection.cpp

bool PeerConnection::changeIceState(IceState newState) {  // line 1232
	if (iceState.exchange(newState) == newState)
		return false;

	std::ostringstream s;
	s << newState;
	PLOG_INFO << "Changed ICE state to " << s.str();

        //---------------- I GET A SEGFAULT HERE-------------------------------//
	// if (newState == IceState::Closed) {  
	// 		auto callback = std::move(iceStateChangeCallback); // steal the callback
	// 		callback(IceState::Closed); // call it synchronously
	// } else { 

        //---------------- THIS IS OK WHEN OUTSIDE IF-ELSE BLOCK----------------------------//
		mProcessor.enqueue(&PeerConnection::trigger<IceState>, shared_from_this(),
		                   &iceStateChangeCallback, newState);
	// }
	return true;
}

whenever I get a failed connection that has logging like so:

2024-04-26 10:55:17.350 ERROR [12911751] [rtc::impl::DtlsTransport::doRecv@990] DTLS recv: Handshake timeout
2024-04-26 10:55:17.350 ERROR [12911751] [rtc::impl::DtlsTransport::doRecv@998] DTLS handshake failed
2024-04-26 10:55:17.350 INFO  [12911751] [rtc::impl::PeerConnection::changeState@1220] Changed state to failed
2024-04-26 10:55:17.350 INFO  [12911751] [rtc::impl::PeerConnection::changeIceState@1238] Changed ICE state to closed
2024-04-26 10:55:17.351 INFO  [12911751] [rtc::impl::PeerConnection::changeState@1220] Changed state to closed
zsh: segmentation fault  bun run main.js

or

2024-04-26 11:14:06.405 INFO  [12930624] [rtc::impl::IceTransport::LogCallback@363] juice: Connectivity timer expired
2024-04-26 11:14:06.405 INFO  [12930624] [rtc::impl::IceTransport::LogCallback@363] juice: Changing state to failed
2024-04-26 11:14:06.405 INFO  [12930624] [rtc::impl::PeerConnection::changeIceState@1238] Changed ICE state to failed
2024-04-26 11:14:06.405 INFO  [12930624] [rtc::impl::PeerConnection::changeState@1220] Changed state to failed
2024-04-26 11:14:06.406 INFO  [12930615] [rtc::impl::PeerConnection::changeIceState@1238] Changed ICE state to closed
2024-04-26 11:14:06.406 INFO  [12930615] [rtc::impl::PeerConnection::changeState@1220] Changed state to closed
zsh: segmentation fault  bun run main.js

my question is whether just enqueuing the callback would lead to any issues.

ibsusu avatar Apr 26 '24 18:04 ibsusu