{"action":"created","issue":{"url":"https://api.github.com/repos/CESNET/Netopeer2/issues/306","repository_url":"https://api.github.com/repos/CESNET/Netopeer2","labels_url":"https://api.github.com/repos/CESNET/Netopeer2/issues/306/labels{/name}","comments_url":"https://api.github.com/repos/CESNET/Netopeer2/issues/306/comments","events_url":"https://api.github.com/repos/CESNET/Netopeer2/issues/306/events","html_url":"https://github.com/CESNET/Netopeer2/issues/306","id":346787697,"node_id":"MDU6SXNzdWUzNDY3ODc2OTc=","number":306,"title":"Segmentation fault or lockup when terminating netopeer2-server with signal","user":{"login":"alangefe","id":29665480,"node_id":"MDQ6VXNlcjI5NjY1NDgw","avatar_url":"https://avatars1.githubusercontent.com/u/29665480?v=4","gravatar_id":"","url":"https://api.github.com/users/alangefe","html_url":"https://github.com/alangefe","followers_url":"https://api.github.com/users/alangefe/followers","following_url":"https://api.github.com/users/alangefe/following{/other_user}","gists_url":"https://api.github.com/users/alangefe/gists{/gist_id}","starred_url":"https://api.github.com/users/alangefe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alangefe/subscriptions","organizations_url":"https://api.github.com/users/alangefe/orgs","repos_url":"https://api.github.com/users/alangefe/repos","events_url":"https://api.github.com/users/alangefe/events{/privacy}","received_events_url":"https://api.github.com/users/alangefe/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-01T22:07:59Z","updated_at":"2018-08-02T07:49:37Z","closed_at":"2018-08-02T07:49:20Z","author_association":"CONTRIBUTOR","body":"When netopeer2-server is sent a signal to terminate it (e.g., `SIGTERM`), it will intermittently crash or lock up, beginning in 3f4bc5e.\r\n\r\nThe problem was introduced by the reordering of `main()`'s cleanup label in 3f4bc5e. `sr_disconnect()` will free `np2srv.sr_conn` when it calls `cl_connection_cleanup()`. The subsequent call to `nc_ps_clear()` results in calls that attempt to use the freed `sr_conn_ctx_t`. (Stack traces are included below.) The contents of the memory are undefined at this point, so any number of things can happen, including a segmentation fault or a lockup when attempting to acquire a freed lock.\r\n\r\nHere is a stack trace for the case where memory from the freed `sr_conn_ctx_t` is used, resulting in a segmentation fault:\r\n\r\n```\r\n#0  sr_uint32_to_buff () at sysrepo/src/common/sr_utils.c:75\r\n#1  cl_message_send () at sysrepo/src/clientlib/cl_common.c:156\r\n#2  cl_request_process () at sysrepo/src/clientlib/cl_common.c:498\r\n#3  sr_session_stop () at sysrepo/src/clientlib/client_library.c:568\r\n#4  free_ds () at netopeer2/server/main.c:296\r\n#5  nc_session_free () at libnetconf2/src/session.c:617\r\n#6  nc_ps_clear () at libnetconf2/src/session_server.c:1573\r\n#7  main () at netopeer2/server/main.c:1576\r\n```\r\n\r\nAnd here is a stack trace for the case where the code attempts to acquire the lock on the freed `sr_conn_ctx_t`, resulting in a lockup:\r\n\r\n```\r\n#0  __lll_lock_wait () from libpthread.so.0\r\n#1  pthread_mutex_lock () from libpthread.so.0\r\n#2  cl_request_process () at sysrepo/src/clientlib/cl_common.c:495\r\n#3  sr_session_stop () at sysrepo/src/clientlib/client_library.c:568\r\n#4  free_ds () at netopeer2/server/main.c:296\r\n#5  nc_session_free () at libnetconf2/src/session.c:617\r\n#6  nc_ps_clear () at libnetconf2/src/session_server.c:1597\r\n#7  main () at netopeer2/server/main.c:1576\r\n```"},"comment":{"url":"https://api.github.com/repos/CESNET/Netopeer2/issues/comments/409838449","html_url":"https://github.com/CESNET/Netopeer2/issues/306#issuecomment-409838449","issue_url":"https://api.github.com/repos/CESNET/Netopeer2/issues/306","id":409838449,"node_id":"MDEyOklzc3VlQ29tbWVudDQwOTgzODQ0OQ==","user":{"login":"michalvasko","id":12510224,"node_id":"MDQ6VXNlcjEyNTEwMjI0","avatar_url":"https://avatars3.githubusercontent.com/u/12510224?v=4","gravatar_id":"","url":"https://api.github.com/users/michalvasko","html_url":"https://github.com/michalvasko","followers_url":"https://api.github.com/users/michalvasko/followers","following_url":"https://api.github.com/users/michalvasko/following{/other_user}","gists_url":"https://api.github.com/users/michalvasko/gists{/gist_id}","starred_url":"https://api.github.com/users/michalvasko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michalvasko/subscriptions","organizations_url":"https://api.github.com/users/michalvasko/orgs","repos_url":"https://api.github.com/users/michalvasko/repos","events_url":"https://api.github.com/users/michalvasko/events{/privacy}","received_events_url":"https://api.github.com/users/michalvasko/received_events","type":"User","site_admin":false},"created_at":"2018-08-02T07:49:37Z","updated_at":"2018-08-02T07:49:37Z","author_association":"CONTRIBUTOR","body":"Hi,\r\nyou are right, sorry about that.\r\n\r\nRegards,\r\nMichal"}}
{"actor":{"display_login":"michalvasko"}}