AravisProject / aravis

A vision library for genicam based cameras
GNU Lesser General Public License v2.1
904 stars 334 forks source link

Packet socket mode and callback causes segfault on stream start #941

Open paulsammut opened 2 months ago

paulsammut commented 2 months ago

Describe the bug When running with Packet socket mode enabled I get a segfault on stream start.

To Reproduce Run packet socket mode using a callback and get segfault on stream start.

Expected behavior Run packet socket mode using a callback without segfault

Camera description:

Platform description:

Additional context My code uses a callback to service frame buffers. I am setting priority realtime to 10, and enabling packet socket mode by running sudo setcap cap_net_raw+ep.

With the same code I do not get this error under the following conditions:

Note When I run with ARV_DEBUG logging enabled or in a Debug build mode this segfault becomes harder to trigger. I have to create a script to start/stop the stream continuously for hundreds of times before hitting the segfault. If I run without AVR_DEBUG logging and in an optimized build I get the segfault on every stream start.

The segfault is happening due to a null dereference of frame in this line.

Stack trace of offending code:

#0  0x0000000003143899 in _find_frame_data (thread_data=0x7fb92067b000, packet=0x7fb94d6000ac, packet_size=62, frame_id=3759, packet_id=1580364, read_count=62, time_us=27579292116) at ./third-party/aravis/src/arvgvstream.c:384
#1  0x000000000314299c in _process_packet (thread_data=0x7fb92067b000, packet=0x7fb94d6000ac, packet_size=62, time_us=27579292116) at ./third-party/aravis/src/arvgvstream.c:899
#2  0x0000000003141af2 in _ring_buffer_loop (thread_data=0x7fb92067b000) at ./third-party/aravis/src/arvgvstream.c:1336
#3  0x00000000031414d8 in arv_gv_stream_thread (data=0x7fb92067b000) at ./third-party/aravis/src/arvgvstream.c:1383
#4  0x000000000341bbf7 in g_thread_proxy (data=0x7fb920608940) at gthread.c:784
#5  0x00007fb9a68b96d7 in start_thread () from /lib64/libc.so.6
#6  0x00007fb9a693d60c in clone3 () from /lib64/libc.so.6

Info on locals showing frame being null:

(gdb) info locals
frame = 0x0
buffer = 0x7fb8b40ec770
iter = 0x0
n_packets = 0
frame_id_inc = 1
extended_ids = 0

Output before segfault:

[22:40:20.441] ๐Ÿ…ธ interface> [GvDiscoverSocket::new] Add interface 127.0.0.1 (127.0.0.1)
[22:40:20.441] ๐Ÿ…ธ interface> [GvDiscoverSocket::new] Add interface 192.168.251.11 (192.168.251.127)
[22:40:20.441] ๐Ÿ…ธ interface> [GvDiscoverSocket::new] Add interface 192.168.251.131 (192.168.251.255)
[22:40:20.441] ๐Ÿ…ธ interface> [GvDiscoverSocket::new] Add interface 100.98.90.30 (100.98.90.31)
[22:40:20.445] ๐Ÿ…ธ interface> [GvInterface::discovery] Device 'Lucid Vision Labs-PHX124S-M-XXXXXX' found (interface 192.168.251.131) user_id '' - MAC '1c:0f:af:06:fb:2b'
[22:40:20.445] ๐Ÿ…ธ device> [GvDevice::new] Interface address = 192.168.251.131
[22:40:20.445] ๐Ÿ…ธ device> [GvDevice::new] Device address = 192.168.251.210
[22:40:20.451] ๐Ÿ…ธ device> [GvDevice::load_genicam] xml url = 'Local:Lucid_Vision_Labs_PHX124S-M_rev1_0_db4aaad522077f99e65fbd6c854ec858.zip;800ea2c8;1080f' at 0x200
[22:40:20.451] ๐Ÿ…ธ device> [GvDevice::load_genicam] Xml address = 0x800ea2c8 - size = 0x1080f - Lucid_Vision_Labs_PHX124S-M_rev1_0_db4aaad522077f99e65fbd6c854ec858.zip
[22:40:20.547] ๐Ÿ…ณ device> [GvDevice::Heartbeat] Ack value = 2
[22:40:20.998] ๐Ÿ…ธ device> [GvDevice::load_genicam] Zipped xml data
[22:40:21.046] ๐Ÿ…ธ device> [GvDevice::new] Device endianness = big
[22:40:21.046] ๐Ÿ…ธ device> [GvDevice::new] Packet resend     = yes
[22:40:21.046] ๐Ÿ…ธ device> [GvDevice::new] Write memory      = yes
[22:40:21.046] ๐Ÿ…ธ device> [GvDevice::new] Legacy endianness handling = no
[INFO] [1726292421.049614141] [cam10.genicam]: arv_camera_new call done - took: 4414444237ns
[22:40:21.094] ๐Ÿ…ธ device> [GvDevice::auto_packet_size] Try packet size = 8999 (8999 - min: 576 - max: 9000 - inc: 1)
[22:40:21.121] ๐Ÿ…ธ device> [GvDevice::auto_packet_size] Packet size set to 8999 bytes
....
[INFO] [1726292834.012029736] [cam1.genicam]: Creating stream in id: 40474
[22:47:14.013] ๐Ÿ…ธ device> [GvDevice::create_stream] Number of stream channels = 1
[22:47:14.013] ๐Ÿ…ธ stream> [GvStream::stream_new] Stream channel = 0
[22:47:14.018] ๐Ÿ…ธ stream> [GvStream::stream_new] Packet size = 8999 byte(s)
[22:47:14.024] ๐Ÿ…ธ stream> [GvStream::stream_new] Destination stream port = 44308
[22:47:14.024] ๐Ÿ…ธ stream> [GvStream::stream_new] Source stream port = 49154
[INFO] [1726292834.024823724] [cam1.genicam]: Stream cb called in 51554
[INFO] [1726292834.025043091] [cam1.genicam]: Set stream thread realtime priority to 10
[22:47:14.042] ๐Ÿ…ธ stream> [GvStream::loop] Packet socket method
[22:47:14.070] ๐Ÿ…ณ device> [GvDevice::Heartbeat] Ack value = 2
[22:47:14.084] ๐Ÿ…ณ device> [GvDevice::Heartbeat] Ack value = 2
[INFO] [1726292834.092107699] [cam1.genicam]: Enabling performance improvements for GigE Vision cameras
[INFO] [1726292834.094027375] [cam1.genicam]: Created 32 buffers of size 16200000 bytes
Segmentation fault (core dumped)
aldoshkind commented 1 day ago

Hi! Faced same problem on version 0.9.0. Running from docker. Camera is Lucid Vision Labs-TRI028S-M

EmmanuelP commented 10 hours ago

Please try #959