2005年4月3日 星期日

TIME_WAIT state

[lang_zh]
在寫計網作業時,發現只要有 client 連進來,在 httpd 砍掉之後,沒辦法馬上再 bind 同一個 port。netstat 看到了 TIME_WAIT。

Active close 一個 connection 時,必須在 TIME_WAIT state 等待 2 x MSL (/maximum segment lifetime/) 的時間。RFC 1122 的建議值是 120 秒。但是 Linux 的實作上 follow BSD,把 MSL 設為 30 秒,net/ipv4/tcp_minisocks.c 裡面有這段註解:
[/lang_zh]

[lang_en]
When I wrote my Computer Network's homework, I found that binding to the same port will be failed after a client comes in and stop the httpd. I see TIME_WAIT state when execute netstat.

One should wait in TIME_WAIT state for 2 x MSL (/maximum segment lifetime/) after close one connection. The suggestion time interval in RFC 1122 is 120 seconds. But the implementation of Linux follows BSD, which set MSL to 30 seconds. There's a comment in net/ipv4/tcp_minisocks.c:
[/lang_en]


* [ BTW Linux. following BSD, violates this requirement waiting
* only for 60sec, we should wait at least for 240 secs.
* Well, 240 consumes too much of resources 8)
* ]



[lang_zh]
試了一下時間,真的是一分鐘 Q_Q 本來是在做測試,懶得把 port 寫在參數裡面。看來得辛苦一點點啦 XD

BTW, Unix Network Programming 真是好書呀!!

Update:
用 setsockopt 打開 SO_REUSEADDR 可以解決這個問題
[/lang_zh]

[lang_en]
I observed the time, and it really about 1 minute Q_Q So I should add a port to the argument :/

BTW, Unix Network Programming is really a great book!

Update:
Use setsockopt to enable SO_REUSEADDR will solve this problem.
[/lang_en]

沒有留言: