Mac OS X'te TIME_WAIT'lerim nerede?


9

TIME_WAITMac OS X'te sürüm yok

Normalde, bir TCP bağlantısı kapatıldığında, close()ilk olarak adlandırılan taraftaki soket durumunda kalır TIME_WAIT.

Eşlerden biri bir Mac OS X (Lion) makinesi olduğunda , Mac tarafında ilk olarak çağrılırsa Mac'te hayır TIME_WAITlistelenir . Ancak, soket gibi görünüyor olduğunu aslında aramaya çalışıyorum, çünkü devlet (soket seçeneğini kullanmadan tekrar ) neden başarısız.netstat -anclose()TIME_WAITlisten()SO_REUSEADDRlisten()

2 * MSL (Mac OS X Lion'da bildirildiği gibi 15 saniye olan Maksimum Segment Ömrü sysctl net.inet.tcp.msl) beklemesi TIME_WAITdurumu temizler ve listen()hatasız olarak tekrar çağrılabilir.

Soketi neden göremiyorum TIME_WAIT?

Test yapmak

İşte Python'da iki basit test programı.

Sunucu

#!/usr/bin/env python

import socket

HOST = ''
PORT = 50007
l = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
l.bind((HOST, PORT))
l.listen(1)
print("Listening on %d" % PORT)
(s, _) = l.accept()
print("Connected")
raw_input("Press <enter> to close...")
l.close()
s.close()
print("Closed")

müşteri

#!/usr/bin/env python

import socket
import sys

HOST = sys.argv[1]
PORT = 50007

print("Opening connection to server")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
raw_input("Press <enter> to close...")
s.close()
print("Closed")

Hem sunucuyu hem de istemciyi iki farklı Linux makinesinde çalıştırırken, <enter>aramak için basan eş close()ilk TIME_WAITolarak beklendiği gibi olur :

$ ./server-timewait.py 
Listening on 50007
Connected
Press <enter> to close...
Closed
$ netstat -an | grep 50007
tcp        0      0 172.16.185.219:50007    172.16.185.42:49818     TIME_WAIT  
$ 

Eşlerden biri Mac (OS X Lion çalıştıran) TIME_WAITolduğunda netstat -an | grep 50007, Mac'te ilk kapattıktan sonra hiç bir zaman göremiyorum .


İyi soru. Aynı şeyi kendim görüyor ve
— netstat'a

2
FWIW, sudo lsof -i -Pzaten çıkmış olan işlemler için de TIME_WAIT durumunu göstermez.
— natevw

@natevw Yalnız olmadığımı bilmek mutlu. :-)
— mgd

Yanıtlar:


2

Bu hata raporu , sorunun netstat uygulamasında olduğunu iddia eder . Hata raporuna eklenen kod, TIME_WAIT durumundaki soketleri doğru gösteriyor. Aşağıdaki satırları kaldırmanız gerekiyor

if (lip == INADDR_LOCALHOST ||
  lip == INADDR_ANY
  ) { continue; }

localhost'a bağlı soketleri göstermesini sağlamak için.


0

Bu bir cevap değil, ama birisi bundan daha fazlasını çıkarabilir.

tcpdump -i lo0 -vv port 50007

## Press Enter at the server window

# Server send a FIN (note the flag)
23:33:04.283768 IP (tos 0x0, ttl 64, id 4134, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->2c9c)!)
    localhost.50007 > localhost.56030: Flags [F.], cksum 0xfe28 (incorrect -> 0xeff9), seq 1, ack 1, win 9186, options [nop,nop,TS val 432165676 ecr 432157913], length 0

# Client send back ACK
23:33:04.283803 IP (tos 0x0, ttl 64, id 44906, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->8d57)!)
    localhost.56030 > localhost.50007: Flags [.], cksum 0xfe28 (incorrect -> 0xd1a6), seq 1, ack 2, win 9186, options [nop,nop,TS val 432165676 ecr 432165676], length 0

# Server confirm the ACK is received
23:33:04.283812 IP (tos 0x0, ttl 64, id 18284, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->f555)!)
    localhost.50007 > localhost.56030: Flags [.], cksum 0xfe28 (incorrect -> 0xd1a6), seq 2, ack 1, win 9186, options [nop,nop,TS val 432165676 ecr 432165676], length 0

## After this point, the server process is actually exit but client still running.
## It's strange that re-run server script gives "OSError: [Errno 48] Address already in use"
## and netstat shows this connection is in CLOSE_WAIT status

## Press Enter at the client window

# Client send a FIN to server
23:33:09.731728 IP (tos 0x0, ttl 64, id 51478, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->73ab)!)
    localhost.56030 > localhost.50007: Flags [F.], cksum 0xfe28 (incorrect -> 0xbcb6), seq 1, ack 2, win 9186, options [nop,nop,TS val 432171035 ecr 432165676], length 0

# WTH!? Who send back this packet? The server process is closed!
23:33:09.731764 IP (tos 0x0, ttl 64, id 18754, offset 0, flags [DF], proto TCP (6), length 52, bad cksum 0 (->f37f)!)
    localhost.50007 > localhost.56030: Flags [.], cksum 0xfe28 (incorrect -> 0xa7c7), seq 2, ack 2, win 9186, options [nop,nop,TS val 432171035 ecr 432171035], length 0

"WTH !? Bu paketi kim geri gönderiyor? Sunucu işlemi kapalı!" TIME_WAIT durumunda olan sunucu tarafından gönderilmiş gibi görünüyor, çünkü bu ilk FIN'i gönderen kısım. Sunucu işlemi sonlandırılsa da, TCP yığını son ACK'yı göndermek için bağlantının durumunu korur.
— neverov
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.