{"action":"created","issue":{"url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9944","repository_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr","labels_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9944/labels{/name}","comments_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9944/comments","events_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9944/events","html_url":"https://github.com/zephyrproject-rtos/zephyr/issues/9944","id":359487143,"node_id":"MDU6SXNzdWUzNTk0ODcxNDM=","number":9944,"title":"sockets: Connect doesn't send new SYN in case the first connection attempt fails","user":{"login":"leodido99","id":279405,"node_id":"MDQ6VXNlcjI3OTQwNQ==","avatar_url":"https://avatars3.githubusercontent.com/u/279405?v=4","gravatar_id":"","url":"https://api.github.com/users/leodido99","html_url":"https://github.com/leodido99","followers_url":"https://api.github.com/users/leodido99/followers","following_url":"https://api.github.com/users/leodido99/following{/other_user}","gists_url":"https://api.github.com/users/leodido99/gists{/gist_id}","starred_url":"https://api.github.com/users/leodido99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leodido99/subscriptions","organizations_url":"https://api.github.com/users/leodido99/orgs","repos_url":"https://api.github.com/users/leodido99/repos","events_url":"https://api.github.com/users/leodido99/events{/privacy}","received_events_url":"https://api.github.com/users/leodido99/received_events","type":"User","site_admin":false},"labels":[{"id":700751655,"node_id":"MDU6TGFiZWw3MDA3NTE2NTU=","url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/labels/area:%20Networking","name":"area: Networking","color":"c5def5","default":false},{"id":999204828,"node_id":"MDU6TGFiZWw5OTkyMDQ4Mjg=","url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/labels/area:%20Sockets","name":"area: Sockets","color":"513ea8","default":false},{"id":383053976,"node_id":"MDU6TGFiZWwzODMwNTM5NzY=","url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/labels/bug","name":"bug","color":"e99695","default":true},{"id":636351494,"node_id":"MDU6TGFiZWw2MzYzNTE0OTQ=","url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/labels/priority:%20medium","name":"priority: medium","color":"d93f0b","default":false}],"state":"open","locked":false,"assignee":{"login":"jukkar","id":1098415,"node_id":"MDQ6VXNlcjEwOTg0MTU=","avatar_url":"https://avatars3.githubusercontent.com/u/1098415?v=4","gravatar_id":"","url":"https://api.github.com/users/jukkar","html_url":"https://github.com/jukkar","followers_url":"https://api.github.com/users/jukkar/followers","following_url":"https://api.github.com/users/jukkar/following{/other_user}","gists_url":"https://api.github.com/users/jukkar/gists{/gist_id}","starred_url":"https://api.github.com/users/jukkar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jukkar/subscriptions","organizations_url":"https://api.github.com/users/jukkar/orgs","repos_url":"https://api.github.com/users/jukkar/repos","events_url":"https://api.github.com/users/jukkar/events{/privacy}","received_events_url":"https://api.github.com/users/jukkar/received_events","type":"User","site_admin":false},"assignees":[{"login":"jukkar","id":1098415,"node_id":"MDQ6VXNlcjEwOTg0MTU=","avatar_url":"https://avatars3.githubusercontent.com/u/1098415?v=4","gravatar_id":"","url":"https://api.github.com/users/jukkar","html_url":"https://github.com/jukkar","followers_url":"https://api.github.com/users/jukkar/followers","following_url":"https://api.github.com/users/jukkar/following{/other_user}","gists_url":"https://api.github.com/users/jukkar/gists{/gist_id}","starred_url":"https://api.github.com/users/jukkar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jukkar/subscriptions","organizations_url":"https://api.github.com/users/jukkar/orgs","repos_url":"https://api.github.com/users/jukkar/repos","events_url":"https://api.github.com/users/jukkar/events{/privacy}","received_events_url":"https://api.github.com/users/jukkar/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2018-09-12T13:43:20Z","updated_at":"2018-12-03T18:04:43Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"In the current implementation of the sockets, when doing a connect call, if the remote doesn't reply with SYN, ACK then the call will never return and no SYN will ever be re-sent.\r\n\r\nThis is because _impl_zsock_connect calls net_context_connect with a timeout value of K_FOREVER that means that after sending the SYN the function will wait forever for an answer, if none comes then we are stuck.\r\nI think the comment of net_context_connect would benefit in being clarified because it reads like this:\r\n```\r\n * @param timeout    The timeout value for the connection. Possible values:\r\n *                   * K_NO_WAIT: this function will return immediately,\r\n *                   * K_FOREVER: this function will block until the\r\n *                                      connection is established,\r\n *                   * >0: this function will wait the specified ms.\r\n```\r\n\r\nIt is blocking until the connection is established, however it won't resend any SYN.\r\nI personally made a modification so I can work with them but it changes the behaviours of the sockets to not being blocking. In Linux, correct me if I'm wrong, but by default sockets are blocking and on connect, the SYN will actually be resent until an answer is received at which point it will return.\r\n\r\nHere is my modification, I had to do the net_conn_unregister otherwise, on the retries net_tcp_register complains a connection handler is already registered.\r\n```\r\n\terr = net_context_connect(ctx, addr, addrlen, NULL, TCP_CONNECT_TIMEOUT, NULL);\r\n\tif (err < 0) {\r\n\t\t/* Cannot connect, we need to unregister the\r\n\t\t * connection handler, otherwise net_tcp_register\r\n\t\t * will complain during the next connection attempt\r\n\t\t */\r\n\t\tif (net_conn_unregister(ctx->conn_handler) < 0) {\r\n\t\t\tSYS_LOG_WRN(\"Cannot unregister socket connection handler\");\r\n\t\t}\r\n\t\terrno = -err;\r\n\t\treturn -1;\r\n\t}\r\n```\r\nWith this modification I can see on Wireshark that the new SYN are sent at every call, the only doubt I have is regarding the local port number, which stays the same on all retries. In net app I noticed the port is forced to be changed between each retries however I looked around in RFC etc... and didn't find anything that said this is mandatory so I left it like that.\r\nIn my opinion, to make a proper implementation you'd have to check the SOCK_NONBLOCK flag and then either do a loop in connect or let user call connect each time in case of non blocking."},"comment":{"url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/comments/443807925","html_url":"https://github.com/zephyrproject-rtos/zephyr/issues/9944#issuecomment-443807925","issue_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9944","id":443807925,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MzgwNzkyNQ==","user":{"login":"pfalcon","id":500451,"node_id":"MDQ6VXNlcjUwMDQ1MQ==","avatar_url":"https://avatars3.githubusercontent.com/u/500451?v=4","gravatar_id":"","url":"https://api.github.com/users/pfalcon","html_url":"https://github.com/pfalcon","followers_url":"https://api.github.com/users/pfalcon/followers","following_url":"https://api.github.com/users/pfalcon/following{/other_user}","gists_url":"https://api.github.com/users/pfalcon/gists{/gist_id}","starred_url":"https://api.github.com/users/pfalcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfalcon/subscriptions","organizations_url":"https://api.github.com/users/pfalcon/orgs","repos_url":"https://api.github.com/users/pfalcon/repos","events_url":"https://api.github.com/users/pfalcon/events{/privacy}","received_events_url":"https://api.github.com/users/pfalcon/received_events","type":"User","site_admin":false},"created_at":"2018-12-03T18:04:42Z","updated_at":"2018-12-03T18:04:42Z","author_association":"MEMBER","body":"Now all hopes are on https://github.com/zephyrproject-rtos/zephyr/pull/11443 to resolve this issue.\r\n"}}
{"actor":{"display_login":"pfalcon"}}