[Libwebsockets] Segfault

Jack Mitchell ml at communistcode.co.uk
Fri Jan 18 16:43:51 CET 2013


On 18/01/13 15:42, Jack Mitchell wrote:
> On 18/01/13 14:04, "Andy Green (林安廸)" wrote:
>> On 18/01/13 21:20, the mail apparently from Jack Mitchell included:
>>
>> Hi -
>>
>>> Today I tried out the latest libwebsockets master in my embedded
>>> application and gave it a good thrashing. I managed to reproduce a
>>> segfault a few times - I have had this issue before but thought I had
>>> fixed it but it has reared it's ugly head again in this new release. I
>>
>> Hm sorry to hear that but I am glad to hear you are beating on the 
>> library HEAD.
>>
>>> have attached a valgrind trace below in the hope that someone could 
>>> help
>>> me out.
>>>
>>> I think it is trying to write to a dead socket (null pointer) and
>>> bailing out. Should there be some extra error checking somewhere to
>>> ensure that a dead socket is never written to?
>>
>> Until this week it would have been too expensive, but with the new 
>> lookup array approach it should be possible to cheaply confirm the 
>> struct websocket you have hold of still jibes with the pollfd it 
>> claims to hold and the fds match.
>>
>> I added an api lws_confirm_legit_wsi()
>>
>> http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/commit/?id=acbaee649ab62beb34609d4b79e8814a2913430f 
>>
>>
>> and used it on libwebsocket_write... if you think that's the problem 
>> you can sprinkle them around and see if it fires.  It looks for any 
>> inconsistency between what the struct websocket thinks its position 
>> in in the polling table and what the polling table thinks.
>>
>> I wasn't really able to tie up the valgrind log with the idea 
>> something blows segfaults.  The log shows a memcpy inside deflate is 
>> reading 2 bytes it shouldn't?
>>
>> -Andy
>>
>>> I'm going to investigate some more and will let you know if I find a
>>> solution!
>>>
>>> <snip>
>>>
>>>
>>>
>>
>
> Hi Andy,
>
> I turned the DEBUG levels right up (1 | 2 | 4 | 8) and it stopped the
> segfault. I would assume this means that somewhere there is maybe some
> error checking code that the debug ifdefs out?
>
> Jack.
>
>
>

Below is a log of me thrashing it so you can see which parts of the code 
I am giving a good kicking.

Device (0) : FPGA Read Function took 122ms
[1358513556:7875] DEBUG: accepted new conn  port 42586 on fd=26
[1358513556:7879] INFO: insert_wsi_socket_into_fds: wsi=0x17ad80, 
sock=26, fds pos=4
[1358513556:7881] DEBUG: Session Socket 0x170c48 (fd=27) dead
[1358513556:7896] DEBUG: libwebsocket_close_and_free_session: 
just_kill_connection
[1358513556:7898] INFO: remove_wsi_socket_from_fds: wsi=0x170c48, 
sock=27, fds pos=3
[1358513556:7901] DEBUG: calling back CLOSED
[1358513556:7904] DEBUG: closing: shutdown returned 107
[1358513556:8930] DEBUG: accepted new conn  port 42587 on fd=27
[1358513556:8933] INFO: insert_wsi_socket_into_fds: wsi=0x170c48, 
sock=27, fds pos=4
[1358513556:8934] DEBUG: Session Socket 0x17ad80 (fd=26) dead
[1358513556:8934] DEBUG: libwebsocket_close_and_free_session: 
just_kill_connection
[1358513556:8935] INFO: remove_wsi_socket_from_fds: wsi=0x17ad80, 
sock=26, fds pos=3
[1358513556:8936] DEBUG: calling back CLOSED
[1358513556:8938] DEBUG: closing: shutdown returned 107
[1358513557:0161] DEBUG: ERROR writing len 63 to socket -1
ERROR: webSock_genericSendRecieve: Socket Generic: Failed to write to 
socket!
[1358513557:0442] DEBUG: ERROR writing len 206 to socket -1
ERROR: webSock_writeJsonObject: Socket Generic: Failed to write json 
object to socket!
[1358513557:0521] DEBUG: ERROR writing len 7 to socket -1
ERROR: webSock_genericSendRecieve: Socket Generic: Failed to write to 
socket!
[1358513557:0727] DEBUG: ERROR writing len 20 to socket -1
ERROR: webSock_writeJsonObject: Socket Generic: Failed to write json 
object to socket!
[1358513557:0790] DEBUG: ERROR writing len 7 to socket -1
ERROR: webSock_genericSendRecieve: Socket Generic: Failed to write to 
socket!
[1358513557:1329] DEBUG: accepted new conn  port 42589 on fd=26
[1358513557:1331] INFO: insert_wsi_socket_into_fds: wsi=0x17b3d0, 
sock=26, fds pos=4
[1358513557:1332] DEBUG: Session Socket 0x170c48 (fd=27) dead
[1358513557:1333] DEBUG: libwebsocket_close_and_free_session: 
just_kill_connection
[1358513557:1334] INFO: remove_wsi_socket_from_fds: wsi=0x170c48, 
sock=27, fds pos=3
[1358513557:1335] DEBUG: calling back CLOSED
[1358513557:1336] DEBUG: closing: shutdown returned 107
[1358513557:2357] DEBUG: accepted new conn  port 42590 on fd=27
[1358513557:2360] INFO: insert_wsi_socket_into_fds: wsi=0x170c48, 
sock=27, fds pos=4
[1358513557:2361] DEBUG: Session Socket 0x17b3d0 (fd=26) dead
[1358513557:2362] DEBUG: libwebsocket_close_and_free_session: 
just_kill_connection
[1358513557:2363] INFO: remove_wsi_socket_from_fds: wsi=0x17b3d0, 
sock=26, fds pos=3
[1358513557:2363] DEBUG: calling back CLOSED
[1358513557:2365] DEBUG: closing: shutdown returned 107
[1358513557:3503] DEBUG: ERROR writing len 63 to socket -1
ERROR: webSock_genericSendRecieve: Socket Generic: Failed to write to 
socket!
[1358513557:3631] DEBUG: ERROR writing len 206 to socket -1
ERROR: webSock_writeJsonObject: Socket Generic: Failed to write json 
object to socket!
[1358513557:3731] DEBUG: ERROR writing len 7 to socket -1
ERROR: webSock_genericSendRecieve: Socket Generic: Failed to write to 
socket!
[1358513557:3794] DEBUG: ERROR writing len 20 to socket -1
ERROR: webSock_writeJsonObject: Socket Generic: Failed to write json 
object to socket!
[1358513557:3833] DEBUG: ERROR writing len 7 to socket -1
ERROR: webSock_genericSendRecieve: Socket Generic: Failed to write to 
socket!
[1358513557:4354] DEBUG: accepted new conn  port 42591 on fd=26
[1358513557:4358] INFO: insert_wsi_socket_into_fds: wsi=0x17c208, 
sock=26, fds pos=4
[1358513557:4361] DEBUG: Session Socket 0x170c48 (fd=27) dead
[1358513557:4363] DEBUG: libwebsocket_close_and_free_session: 
just_kill_connection
[1358513557:4365] INFO: remove_wsi_socket_from_fds: wsi=0x170c48, 
sock=27, fds pos=3
[1358513557:4368] DEBUG: calling back CLOSED
[1358513557:4372] DEBUG: closing: shutdown returned 107
[1358513557:5469] DEBUG: ERROR writing len 63 to socket -1
ERROR: webSock_genericSendRecieve: Socket Generic: Failed to write to 
socket!
[1358513557:5579] DEBUG: ERROR writing len 206 to socket -1
ERROR: webSock_writeJsonObject: Socket Generic: Failed to write json 
object to socket!
[1358513557:5627] DEBUG: ERROR writing len 7 to socket -1
ERROR: webSock_genericSendRecieve: Socket Generic: Failed to write to 
socket!
[1358513557:5689] DEBUG: ERROR writing len 20 to socket -1
ERROR: webSock_writeJsonObject: Socket Generic: Failed to write json 
object to socket!
[1358513557:5735] DEBUG: ERROR writing len 7 to socket -1
ERROR: webSock_genericSendRecieve: Socket Generic: Failed to write to 
socket!
[1358513557:6258] DEBUG: accepted new conn  port 42592 on fd=27
[1358513557:6311] INFO: insert_wsi_socket_into_fds: wsi=0x170c48, 
sock=27, fds pos=4
[1358513557:6317] DEBUG: libwebsocket_close_and_free_session: 
just_kill_connection
[1358513557:6336] INFO: remove_wsi_socket_from_fds: wsi=0x17c208, 
sock=26, fds pos=3
[1358513557:6341] DEBUG: calling back CLOSED
[1358513557:6356] DEBUG: closing: shutdown returned 107
Device (0) : FPGA Read Function took 93ms
[1358513557:7407] DEBUG: accepted new conn  port 42593 on fd=26
[1358513557:7429] INFO: insert_wsi_socket_into_fds: wsi=0x17c208, 
sock=26, fds pos=4
[1358513557:7442] DEBUG: Session Socket 0x170c48 (fd=27) dead
[1358513557:7444] DEBUG: libwebsocket_close_and_free_session: 
just_kill_connection
[1358513557:7447] INFO: remove_wsi_socket_from_fds: wsi=0x170c48, 
sock=27, fds pos=3
[1358513557:7449] DEBUG: calling back CLOSED
[1358513557:7452] DEBUG: closing: shutdown returned 107


-- 

   Jack Mitchell (jack at embed.me.uk)
   Embedded Systems Engineer
   http://www.embed.me.uk

--




More information about the Libwebsockets mailing list