#666 Race condition in net.http.request with server_select

Reporter Zash
Owner Nobody
Created
Updated
Stars (0)  
Tags
  • Status-New
  • Priority-Medium
  • Type-Defect
  1. Zash on

    What steps will reproduce the problem? 1. Use server_select 2. Call net.http.request("https://localhost/", ...) 3. Be unlucky What is the expected output? Successful https request. What do you see instead? Traceback, partly obscured by the TLS handshake coroutine: net/http.lua:35: attempt to index local 'req' (a nil value) -- in listener.onconnect() stack traceback: [C]: in function 'handshake' net/server_select.lua:653: in function 'starttls' If both the underlying LuaSocket connect call and the TLS handshake completes straight away then server_select will call the onconnect listener callback before the server.addclient() call in net.http.request() returns the connection handle. The HTTP request object is associated with the connection after addclient returns, so in this case onconnect is called before this happens, which leads to the traceback.

New comment