5

I am implementing a server which accepts many concurrent connections.

I used this structure:

loop(Sock) ->
  case gen_tcp:accept(Sock) of
      {ok, CSock} ->    
          fork_handling_process(CSock);
      {error, Reason} ->
          do_something_else();
  end,
  loop(Sock).

I am wondering if someone sends me a SYN, but never sends me an SYN ACK in response to my server ACK, will my server be blocked forever by that client since I call gen_tcp:accept without a timeout?

By the way I think this situation is hard to emulate, so please let me know if you have ways to try it out.

Thx in advance.

Chi Zhang
  • 771
  • 2
  • 8
  • 22

2 Answers2

4

When you listen/accept its a bit different as you describe:

Some client wants to connect: it sends a SYN, then your operating system sends a SYN/ACK (erlang not involvled), when you get the ACK gen_tcp:accept will return.

When someone sends you SYN's and nothing else (that would be a SYN flood attack if done in a great amount) then operating system resources will be reserved but nothing happens in your erlang code because a three way handshake is not complete yet.

Many operating systems are taking special care of SYN flooding attacks avoiding too much resource consumption.

Peer Stritzinger
  • 8,232
  • 2
  • 30
  • 43
0

The approach you are using appears to be fine. Your server will not block. If something goes wrong I believe that your forked process will receive the error, not the server.

OJ.
  • 28,944
  • 5
  • 56
  • 71