TCP RST 보내기TCP RST 보내기

Posted at 2012. 12. 28. 10:02 | Posted in Server

tcp 소켓을 닫을때 일반적으로는 normal tcp termination(4way closing handshake) 과정을 거치게 된다.

이 때, 소켓을 먼저 close한 쪽에 TIME_WAIT 상태로 소켓이 남아 있게 된다.

만약 서버가 먼저 close한 경우 TIME_WAIT 소켓이 가득차서 더 이상의 소켓을 accept 할 수 없는 상황이 발생할 수 있다.

이럴 때의 대안으로 normal tcp termination이 아닌 abortive close로 TIME_WAIT이 발생하지 않도록 할 수 있다.

(TIME_WAIT 상태가 왜 있는지 정확히 알고, 특정 상황에서만 사용하자.)


SO_LINGER with timeout 0

로 설정하고 close()를 호출하면 TCP FIN 대신 RST 이 나간다.

peer는 그 유명한 "Connection reset by peer" 에러가 발생하게 된다.


상세는 다음 글을 참조하자.

according to "UNIX Network Programming" third edition page 202-203, setting SO_LINGER with timeout 0 prior to calling close() will cause the normal termination sequence not to be initiated.


http://stackoverflow.com/a/13088864


//