FIN_WAIT_2 »óÅ¿¡ ´ëÇÏ¿©
ÀÛ¼ºÀÚ °ü¸®ÀÚ ÀÛ¼º½Ã°£ 2006-05-18 18:22:47
 

FIN_WAIT_2 »óÅ¿¡ ´ëÇÏ¿©


À¯ºÎ¼±  bsyu@kr.ibm.com

°³¿ä 

TCP´Â UDP¿Í´Â ´Þ¸® connection-oriented protocolÀÎ °ü°è·Î, ¿¬°áÀ» ¸Î°Å³ª ƯÈ÷ ²÷À» ¶§, ¸¹Àº È®ÀÎ ÀýÂ÷¸¦ °ÅÄ¡°Ô µË´Ï´Ù. ÀÌ·Î ÀÎÇÏ¿©, server¿Í client °£¿¡ ¾à°£ÀÇ overhead°¡ ÀÖÀ» ¼ö ÀÖ½À´Ï´Ù. ƯÈ÷, web server·Î »ç¿ëµÇ´Â systemÀÇ °æ¿ì, ´ëºÎºÐÀÇ clientµéÀÌ ±×¸® ¾ÈÁ¤ÀûÀÌÁö ¾ÊÀº PC clientÀ̹ǷÎ, connectionÀ» ¸Î´ø client applicationÀÌ crashµÇ´Â °æ¿ì web server¿¡´Â ´Ù¼Ò°£ÀÇ ¹®Á¦°¡ ¹ß»ýÇÒ ¿©Áö°¡ ÀÖ½À´Ï´Ù. °¡Àå ´ëÇ¥ÀûÀÎ ¹®Á¦°¡ FIN_WAIT_2 »óÅÂÀÔ´Ï´Ù. ¿©±â¼­´Â ÀÌ »óÅ°¡ ¹«¾ùÀ» ¶æÇÏ´ÂÁö, ÀÌ·Î ÀÎÇØ ¾î¶² ¹®Á¦°¡ ÀÖÀ» ¼ö ÀÖ´ÂÁö, ¶Ç ±×¿¡ ´ëÇÑ ´ëÃ¥Àº ¹«¾ùÀÎÁö ¾Ë¾Æº¸°Ú½À´Ï´Ù.


TCP socket connection »óÅÂÀÇ Á¾·ù 

´ÙÀ½Àº RFC 793 ¿¡ ³ª¿ÍÀÖ´Â ±×¸²À¸·Î, TCP connectionÀ» ¸Î°í ÀÖ´Â µÎ systemÀÌ Á¤»óÀûÀ¸·Î connectionÀ» ³¡³»´Â °úÁ¤À» º¸¿©ÁÝ´Ï´Ù.

TCP A                TCP B
1. ESTABLISHED    ESTABLISHED
2. (Close)
FIN-WAIT-1 ¡æ <SEQ=100><ACK=300><CTL=FIN,ACK>  ¡æ CLOSE-WAIT
3. FIN-WAIT-2 ¡ç <SEQ=300><ACK=101><CTL=ACK>  ¡ç CLOSE-WAIT
4. (Close) 
TIME-WAIT ¡ç <SEQ=300><ACK=101><CTL=FIN,ACK>  ¡ç LAST-ACK
5. TIME-WAIT ¡æ <SEQ=101><ACK=301><CTL=ACK>  ¡æ CLOSED
6. (2 MSL)   
CLOSED

Normal Close Sequence


¸ÕÀú, A°¡ connectionÀ» close Çϸ鼭, Á¾·á ½ÅÈ£ÀÎ FIN segment¸¦ A°¡ B·Î º¸³»°í, A´Â FIN-WAIT-1 »óÅ·Πµé¾î°©´Ï´Ù. ÀÌ »óÅ¿¡¼­´Â A systemÀÇ user´Â ´õ ÀÌ»óÀÇ SEND´Â »ç¿ëÇÒ ¼ö ¾ø°Ô µÇÁö¸¸, RECEIVE´Â °è¼Ó °¡´ÉÇÕ´Ï´Ù. B°¡ ±× ½ÅÈ£¸¦ ¹ÞÀ¸¸é B´Â CLOSE-WAIT¿¡ µé¾î°¡¸é¼­ ±×¿¡ ´ëÇÑ acknowledge¸¦ º¸³»¿É´Ï´Ù. A´Â À̸¦ ¹ÞÀ¸¸é FIN-WAIT-2 »óÅ°¡ µÇ°í, B´Â connectionÀ» closeÇϸ鼭 ÀÚ½ÅÀÇ FINÀ» º¸³À´Ï´Ù. ÀÌ ¶§ A´Â TIME-WAIT »óÅ°¡ µÇ¾î ÃÖÁ¾ÀûÀ¸·Î B¿ÍÀÇ connectionÀÌ ´ÝÈ÷´ÂÁö È®ÀÎÇÏ°Ô µË´Ï´Ù. Áï, server°¡ client·ÎºÎÅÍ FIN¿¡ ´ëÇÑ ACKÀ» ¹Þ°í³ª¼­, clientÀÇ FINÀ» ±â´Ù¸®´Â »óÅ°¡ FIN-WAIT-2 »óÅÂÀÔ´Ï´Ù. ¹®Á¦´Â, ÀÌ FIN-WAIT-2 »óÅ¿¡ ´ëÇؼ­´Â ¿ø·¡ time-out °ªÀÌ Á¤ÇØÁ® ÀÖÁö ¾Ê¾Æ¼­, client°¡ FINÀ» º¸³»¿À±â Àü¿¡ clientÀÇ applicationÀ̳ª client ÀÚü°¡ crashµÇ´Â °æ¿ì, ¶Ç´Â, client programÀ̳ª server program¿¡ bug°¡ À־ À̸¦ Á¦´ë·Î ó¸® ¸øÇÏ´Â °æ¿ì¿¡´Â, server¿¡ ³²¾ÆÀÖÀ» FIN-WAIT-2 »óÅ´ server°¡ rebootingÇϱâ Àü¿¡´Â ³¡±îÁö ³²¾Æ ÀÖ°Ô µÈ´Ù´Â °ÍÀÔ´Ï´Ù. ÀÌ´Â netstat -a ¸í·É¾î·Î È®ÀÎÇØ º¼ ¼ö Àִµ¥, ÀÌ·¯ÇÑ »óÅÂÀÇ connectionÀÌ ¸¹ÀÌ ½×ÀÌ´Ùº¸¸é ¹®Á¦¸¦ ÀÏÀ¸Å³ ¼öµµ ÀÖ½À´Ï´Ù.


FIN_WAIT_2 ¿¡ ´ëÇÑ ´ëÃ¥ 

°¡Àå ÁÁÀº ÇØ°áÃ¥Àº bug°¡ ÀÖ´Â client ¶Ç´Â server programÀ» ¼öÁ¤ÇÏ´Â °ÍÀÔ´Ï´Ù. ´ëºÎºÐÀÇ ¹®Á¦´Â ±× ¹®Á¦·ÎºÎÅÍ ¹ß»ýÇϱ⠶§¹®ÀÔ´Ï´Ù. Server¿¡¼­ ¿î¿µµÇ´Â °¡Àå ´ëÇ¥ÀûÀÎ applicationÀº Apache webserverÀÏ °ÍÀÔ´Ï´Ù. Apache´Â ÀÌ ¹®Á¦¿¡ ´ëÇÑ ÇØ°áÃ¥À¸·Î lingering_close() ÇÔ¼ö ´ë½Å SO_LINGER ÇÔ¼ö¸¦ »ç¿ëÇϵµ·Ï ±ÇÇϱ⵵ ÇÕ´Ï´Ù. (ÀÚ¼¼ÇÑ °ÍÀº ¾ÆÆÄÄ¡ ȨÆäÀÌÁö www.apache.org¸¦ ÂüÁ¶ÇϽñ⠹ٶø´Ï´Ù.) ´Ù¸¥ UNIXµéÀº FIN-WAIT-2¿¡ ´ëÇØ, time-out °ªÀ» ÁöÁ¤ÇÔÀ¸·Î½á ÀÌ ¹®Á¦¸¦ ȸÇÇÇϵµ·Ï ÇØÁÙ ¼ö ÀÖ°Ô ÇØÁֱ⵵ ÇÕ´Ï´Ù. Solaris, HP/UX, Linux µî ¸¹Àº OS°¡ ÀÌ·¯ÇÑ ±â´ÉÀ» Á¦°øÇÕ´Ï´Ù. À̰͵éÀº RFC 793À» À§¹ÝÇÏ´Â °ÍÀÔ´Ï´Ù¸¸, ÇÊ¿ä¿¡ ÀÇÇØ °¢ vendor°¡ Á¦°øÇÏ´Â °ÍÀÔ´Ï´Ù. AIX´Â (´Ù¸¥ UNIX¿Í ¸¶Âù°¡Áö·Î) TCP keepalive timer¸¦ Á¦°øÇÔÀ¸·Î½á ÀÌ ¹®Á¦¸¦ ÇØ°áÇÕ´Ï´Ù.


# no -a | grep tcp_keep
tcp_keepintvl = 150
tcp_keepidle = 14400

À§ÀÇ °ªÀÌ default °ªÀ̸ç, ÀÌ °æ¿ì, 150 * 500ms clock tick = 75 ÃÊ, ±×¸®°í 14400 * 500ms clock tick = 2 ½Ã°£ÀÌ µË´Ï´Ù.

keepalive timer´Â data segment¸¦ º¸³»¸é¼­ resetµË´Ï´Ù. ¸¸¾à ÁÖ¾îÁø tcp_keepidle tick µ¿¾È ¾Æ¹« data segmentµµ º¸³»ÁöÁö ¾Ê¾Ò´Ù¸é ¸ÕÀú, ù¹ø° keepalive probe packetÀÌ º¸³»Áý´Ï´Ù.

ÀÌ packet¿¡ ´ëÇØ reply°¡ ¾øÀ» °æ¿ì, tcp_keepintvl¿¡ Á¤ÇØÁø tick¸¸Å­À» °£°ÝÀ¸·Î ÇÏ¿©, Ãß°¡ÀÇ keepalive packetÀ» º¸³»°Ô µË´Ï´Ù.

¸¸¾à ÀÌ keepalive¿¡ ´ëÇØ reply°¡ °è¼Ó ¾øÀ» °æ¿ì, ±× connectionÀº closeµË´Ï´Ù. AIX 4.2¿¡¼­´Â TCPTV_KEEPCNT (±âº»°ª 8)¿¡ ÇØ´çÇÏ´Â °³¼öÀÇ probe¿¡ ´ëÇØ ÀÀ´äÀÌ ¾øÀ» °æ¿ì closeµÇ´Âµ¥, AIX 4.3¿¡¼­´Â ÀÌ no attribute°¡ ¾ø¾îÁ³½À´Ï´Ù.

tcp_keepinit´Â Ãʱ⠿¬°á½Ã ÀÀ´äÀÌ ¾øÀ» °æ¿ì¿¡ »ç¿ëµÇ´Â °ªÀÔ´Ï´Ù. µû¶ó¼­, ÀÏ´Ü connectionÀ» ¸Î°í ³ª¼­ ¹ß»ýÇÏ´Â ¹®Á¦¿¡ ´ëÇؼ­´Â Àû¿ëµÇÁö ¾Ê½À´Ï´Ù.

À§¿¡ µû¸£¸é, FIN_WAIT_2°¡ ¹ß»ýÇÏ´Â °æ¿ì, default·Î 2½Ã°£ 10ºÐ ÈÄ¿¡¾ß ±× connectionÀÌ closeµÇµµ·Ï µÇ¾î ÀÖ½À´Ï´Ù. ¸¸¾à, ¸Å¿ì busyÇÑ web serverÀÎ °æ¿ì¿¡´Â ÀÌ °ªµéÀ» Á¶ÀýÇÏ´Â °ÍÀÌ ÇÊ¿äÇÒ ¼ö ÀÖ½À´Ï´Ù.


¸ñ·Ï | ÀÔ·Â | ¼öÁ¤ | ´äº¯ | »èÁ¦