Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tcp.accept can sometimes accept GHOST SOCKETs (previous closed remote connection). #410

Closed
jakitliang opened this issue Sep 29, 2023 · 2 comments

Comments

@jakitliang
Copy link

jakitliang commented Sep 29, 2023

You can test it with your local irb or python or nodejs as a client.

require 'socket'
c = TCPSocket.new 127.0.0.1, 3000
c.write '123'
c.close()
--- Socket = require 'luasocket'
--- local server =  Socket.tcp()
server:bind('127.0.0.1', 3000)
server:listen()

while true do
  r, w, err IO.select({server}, nil, 1)

  if #r > 0
    if r[1] == server then
      local client = server:accpet() -- previous closed client is successfully accepted but this client had closed by ruby already.
      -- You accept A ZOMBIE SOCKET!!!
      msg1, err, msg2 = client.receive()
      client.send(msg1 or msg2)
      client.close()
    end
  end
end

Client only connect The SERVER by 1 TIME.

But Server Would Accept more Than 1 TIME

I mean:

Server -> select()
Client -> connect()
Server -> accept
Client -> send() -> close()
Server -> receive() -> send(response) -> close()
Server -> select()
Server -> accept() -- HERE is the problem, now no client is doing connect().
-- But a GHOST socket being accept()

Express.js and Ruby on Rails Don't have such problem.

Only luasocket have this bug.

@jakitliang jakitliang changed the title tcp.accept sometimes accept a previous closed remote connection. tcp.accept can sometimes accept ZOMBIE SOCKETs (previous closed remote connection). Sep 29, 2023
@jakitliang jakitliang changed the title tcp.accept can sometimes accept ZOMBIE SOCKETs (previous closed remote connection). tcp.accept can sometimes accept GHOST SOCKETs (previous closed remote connection). Sep 30, 2023
@alerque
Copy link
Member

alerque commented Nov 10, 2023

I think it is possible the very old but only recently merged PR #81 might address this issue. Can you check it out again with the current SCM version?

@jakitliang
Copy link
Author

I review this commit and found that there did add a retry by continue.

But really sorry that I can't recheck this issue because my project had replace luasocket into another module Socket.lua.

Sorry again and hope luasocket well in the future!

Best wishes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants