jancona / hpsdrconnector

An OpenWebRX connector for HPSDR radios
Apache License 2.0
9 stars 3 forks source link

Panic when switching receivers in OWRX #10

Closed luarvique closed 11 months ago

luarvique commented 11 months ago

When switching between two HL2 receivers in OpenWebRX, I am seeing the following issue:

Stopping Receiver:

2023-12-02 12:04:38,566 - owrx.source.HL2-1 - INFO - STDOUT: 2023/12/02 12:04:38 client: Received an interrupt, stopping...
2023-12-02 12:04:38,568 - owrx.source.HL2-1 - DEBUG - shut down with RC=0
2023-12-02 12:04:38,568 - owrx.source.HL2-1 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] server(7300): Received server command 'close_receiver:51597'
2023-12-02 12:04:38,574 - owrx.source.HL2-1 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] server(7300): closeReceiver(51597)
2023-12-02 12:04:38,592 - owrx.source.HL2-1 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] Attempting to delete receiver protocol1.Receiver{radio:(*protocol1.Radio)(0x40001300b0), sampleFunc:(func([]hpsdr.ReceiveSample))(0x100430)}
2023-12-02 12:04:38,594 - owrx.source.HL2-1 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] Deleting receiver protocol1.Receiver{radio:(*protocol1.Radio)(0x40001300b0), sampleFunc:(func([]hpsdr.ReceiveSample))(0x100430)}
2023-12-02 12:04:38,607 - owrx.source.HL2-1 - INFO - STDOUT: 2023/12/02 12:04:38 [INFO] server(7300): Closed receiver listening on control port 51597, 0 receivers left
2023-12-02 12:04:38,609 - owrx.source.HL2-1 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] server(7300): Removing listener 0x40001a8000
2023-12-02 12:04:38,612 - owrx.source.HL2-1 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] server(7300): Removed listener 0x40001a8000
2023-12-02 12:04:38,613 - owrx.source.HL2-1 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] server(7300): Closing IQ socket on port 46769
2023-12-02 12:04:38,614 - owrx.source.HL2-1 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] server(7300): Error reading server socket: EOF
2023-12-02 12:04:38,616 - owrx.source.HL2-1 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] server(7300): Error reading control socket: EOF
2023-12-02 12:04:38,678 - owrx.source.HL2-1 - WARNING - STDERR: panic: runtime error: slice bounds out of range [520:60]
2023-12-02 12:04:38,681 - owrx.source.HL2-1 - WARNING - STDERR: 
2023-12-02 12:04:38,684 - owrx.source.HL2-1 - WARNING - STDERR: goroutine 49 [running]:
2023-12-02 12:04:38,687 - owrx.source.HL2-1 - WARNING - STDERR: github.com/jancona/hpsdr/protocol1.(*Radio).receiveSamples(0x40001300b0)
2023-12-02 12:04:38,689 - owrx.source.HL2-1 - WARNING - STDERR:     /home/runner/go/pkg/mod/github.com/jancona/hpsdr@v0.7.0/protocol1/radio.go:376 +0x73c
2023-12-02 12:04:38,690 - owrx.source.HL2-1 - WARNING - STDERR: created by github.com/jancona/hpsdr/protocol1.(*Radio).Start in goroutine 1

Starting Receiver:

2023-12-02 12:04:38,636 - owrx.source.HL2-3 - INFO - Started sdr source: hpsdrconnector --samplerate 384000 --debug --radio 169.254.19.221 --gain 60 --serverPort 7302 --frequency 7150000 -p 57339 -c 60811
2023-12-02 12:04:38,640 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] Debug is on
2023-12-02 12:04:38,644 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] client: No server running, starting one on port 7302
2023-12-02 12:04:38,645 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] client: Server args: [--server --serverPort 7302 --samplerate 384000 --gain 60 --radio 169.254.19.221 --debug]
2023-12-02 12:04:38,656 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] Debug is on
2023-12-02 12:04:38,657 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:38 client: Failed to connect to hpsdrconnector server, exiting: dial tcp [::1]:7302: connect: connection refused
2023-12-02 12:04:38,673 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] server(7302): Starting
2023-12-02 12:04:38,674 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] discoverProtocol1Address: Listening on :0
2023-12-02 12:04:38,679 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:38 [DEBUG] discoverReceive: starting
2023-12-02 12:04:40,661 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:40 client: Failed to connect to hpsdrconnector server, exiting: dial tcp [::1]:7302: connect: connection refused
2023-12-02 12:04:40,674 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:40 [DEBUG] discoverReceive: timeout: read udp [::]:51426: i/o timeout
2023-12-02 12:04:40,675 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:40 [DEBUG] discoverReceive: complete
2023-12-02 12:04:40,676 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:40 Error discovering device, exiting: no device found at 169.254.19.221
2023-12-02 12:04:42,666 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:42 client: Failed to connect to hpsdrconnector server, exiting: dial tcp [::1]:7302: connect: connection refused
2023-12-02 12:04:44,669 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:44 client: Failed to connect to hpsdrconnector server, exiting: dial tcp [::1]:7302: connect: connection refused
2023-12-02 12:04:46,673 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:46 client: Failed to connect to hpsdrconnector server, exiting: dial tcp [::1]:7302: connect: connection refused
2023-12-02 12:04:48,678 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:48 client: Failed to connect to hpsdrconnector server, exiting: dial tcp [::1]:7302: connect: connection refused
2023-12-02 12:04:50,679 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:50 client: Failed to connect to hpsdrconnector server, exiting: dial tcp [::1]:7302: connect: connection refused
2023-12-02 12:04:52,684 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:52 client: Failed to connect to hpsdrconnector server, exiting: dial tcp [::1]:7302: connect: connection refused
2023-12-02 12:04:54,687 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:54 client: Failed to connect to hpsdrconnector server, exiting: dial tcp [::1]:7302: connect: connection refused
2023-12-02 12:04:56,688 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:56 client: Failed to connect to hpsdrconnector server, exiting: dial tcp [::1]:7302: connect: connection refused
2023-12-02 12:04:58,689 - owrx.source.HL2-3 - INFO - STDOUT: 2023/12/02 12:04:58 client: Unable to connect to hpsdrconnector server, exiting: dial tcp [::1]:7302: connect: connection refused
2023-12-02 12:04:58,690 - owrx.source.HL2-3 - DEBUG - shut down with RC=1
2023-12-02 12:04:58,705 - owrx.source.HL2-3 - DEBUG - opening control socket...
2023-12-02 12:04:58,706 - owrx.source.HL2-3 - ERROR - Exception during postStart()
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/owrx/source/__init__.py", line 413, in start
    self.postStart()
  File "/usr/lib/python3/dist-packages/owrx/source/connector.py", line 57, in postStart
    self.controlSocket.connect(("localhost", self.controlPort))
ConnectionRefusedError: [Errno 111] Connection refused

OpenWebRX+ retries opening the second receiver after a while, so it does eventually start working, with a long delay. The original OpenWebRX probably marks the receiver dead. I am currently assuming that the whole problem is caused by this panic when closing the previous device:

2023-12-02 12:04:38,678 - owrx.source.HL2-1 - WARNING - STDERR: panic: runtime error: slice bounds out of range [520:60]
2023-12-02 12:04:38,681 - owrx.source.HL2-1 - WARNING - STDERR: 
2023-12-02 12:04:38,684 - owrx.source.HL2-1 - WARNING - STDERR: goroutine 49 [running]:
2023-12-02 12:04:38,687 - owrx.source.HL2-1 - WARNING - STDERR: github.com/jancona/hpsdr/protocol1.(*Radio).receiveSamples(0x40001300b0)
2023-12-02 12:04:38,689 - owrx.source.HL2-1 - WARNING - STDERR:     /home/runner/go/pkg/mod/github.com/jancona/hpsdr@v0.7.0/protocol1/radio.go:376 +0x73c
2023-12-02 12:04:38,690 - owrx.source.HL2-1 - WARNING - STDERR: created by github.com/jancona/hpsdr/protocol1.(*Radio).Start in goroutine 1

Could you please look into this?

luarvique commented 11 months ago

Found the reason: OWRX devices referring to the same physical HL2 device have to use the same network port. That appears to have fixed things. Sorry for the false alert.

jancona commented 11 months ago

I'm reopening this because the panic shouldn't occur even if things were misconfigured.

jancona commented 11 months ago

Added code to protect against this.