Crash after Websocket close

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Crash after Websocket close

952 次查看
adyr
Contributor V

Hi,

I am using KSDK 1.3 with MQX and building with IAR for a MK66 processor.

I have found that my system crashed at a fault interrupt some time after closing a websocket. The crash was caused by the lwSemaphore code that searches for a semaphore that is being removed. Further investigation showed that there was a corrupted semaphore in the linked list and eventually I found that the session structure was being deleted without destroying the semaphore.

It appears that the httpsrv_ses_free function is called but not the httpsrv_ses_close when the websocket is closed.

I have added to httpsrv_ses_free in httpsrv_task.c:

    if (session)     {   //Adrian Rockall:- make sure the semaphore is destroyed before freeing the memory it sits in         _lwsem_destroy(&session->lock);

        if (session->request.path)         {             _mem_free(session->request.path);         }

That appears to solve the problem but I'm wondering the error is further up the chain with a missing call to httpsrv_ses_close?

I hope this helps anyone suffering the same problem but if anyone has a better solution I would be grateful.

Best regards,

Adrian.

标签 (1)
标记 (1)
0 项奖励
2 回复数

620 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi Adrian:

Thanks for your sharing.

According to the code, this semaphore should be initialized at function httpsrv_ses_init and ended at function httpsrv_ses_close.

In function httpsrv_ses_close, The socket is closed and the semaphore is destroyed.   I am wondering where you close the socket in your project?

Regards

Daniel

0 项奖励

620 次查看
adyr
Contributor V

Hi Daniel,

My memory is a bit fuzzy now but I think it was when the web socket was being closed by the web page. I do have a few places in my project where I call WS_close and I think they are fine.

Should I be calling WS_close from the disconnect call back?

That didn't seem logical as that call back is part of the web socket shutdown procedure and therefore seems wrong to try and close something again part way through closing but maybe that is where I am going wrong.

Best regards,

Adrian.

0 项奖励