FactbirdHQ / ublox-short-range-rs

A driver crate for the entire u-blox short range family in Rust
6 stars 2 forks source link

Closing a peer in WaitingForConnection mode causes undefined behaviour #32

Closed unizippro closed 2 years ago

unizippro commented 2 years ago

Closing a peer after creation before connection is established, is not registered correctly. Since having two connections to the same socket address is not allowed the module throws an error if a reconnection is tried.

This should not be possible, as connect should be blocking, but #30 makes this possible. So it might be classified as a symptom of another bug.

161351 DEBUG [TCP] Opening socket
161352 DEBUG Adding socket! 0 Tcp
161352 DEBUG [TCP] Connect socket
161371 DEBUG Sending command with too long payload (80 bytes) to log! (Connect)
161391 DEBUG [Handle(0)] TCP state change: State::Created -> State::WaitingForConnect
161391 DEBUG [Handle(0)] Updating handle Handle(4)
161391 TRACE [TCP] Connecting socket: Handle(4) to url: tcp://34.253.44.78:8883/?ca=root_ca&cert=cert&privKey=priv_key
161392 DEBUG Network connected!
161392 INFO  MQTT connecting..
161394 ERROR [send] NetworkError::Write
161394 DEBUG Disconnecting!
161394 DEBUG [TCP] Closing socket: Handle(4)    (Close is not registered by module)
161394 DEBUG Removing socket! 4 Some(Tcp)
161412 DEBUG Sending command with too long payload (67 bytes) to log! (DNS)
161443 TRACE [EDM_URC] IPv4ConnectEvent! Channel_id: ChannelId(4)   (Peer now connected at modem)
161443 TRACE [EDM_MAP] Handle(4) tied to ChannelId(4)
161443 DEBUG [Handle(4)] TCP state change: State::WaitingForConnect -> State::Connected
161444 TRACE [URC] PeerConnected
161474 TRACE [URC] PingResponse
161474 DEBUG [TCP] Opening socket
161475 DEBUG Adding socket! 0 Tcp
161476 DEBUG [TCP] Connect socket
161494 DEBUG Sending command with too long payload (80 bytes) to log! (Connect to same IP again)
161514 TRACE Digest ReceivingResponse / b"\xaa\x00\x0b\x00E\r\nERROR\r\nU"
161514 ERROR Received error response InvalidResponse
161515 ERROR InvalidResponse: b"\xaa\x00L\x00DAT+UDCP=\"tcp://34.253.44.78:8883/?ca=root_ca&cert=cert&privKey=priv_key\"\r\nU"

Solution

Block untill state changes? This could cause other issues, as it will cause a stall if the socket ends in this state by mistake.

unizippro commented 2 years ago

Its determined to be a symptom of the #30. If it is to arrise again one could block waiting for the socket to open, but it requires checking the WaitingForConnected state can not be reached without having sent the open peer command.