CLOSE_WAIT이 발생하여 서버가 먹통이 되는 현상이 생기는데여??

MackTheKnife의 이미지

Multi Thread로 작성한 소스에서 시간이 지나면 CLOSE_WAIT 이 증가하여서
Server가 accept까지만되고 쓰레드도 생성이 되지않습니다.

소스.

main()
{
	listen()
	select()

	sockfd=accept()
	sockfd를 queue에 넣어서 보관
	pthread_create(...AcceptThread,..);
}
AcceptThread()
{\
	queue에서 sockfd를 꺼냄..//mutex적용
}

server와 client는 매번 connection을 연결하고 close합니다.
초당 4-5번정도의 connection이 맺어지구여.

근데 시간이 지나면 CLOSE_WAIT 의 갯수가 증가하여서 Server에서
accept한 후에 소켓에서 데이터를 읽지를 못합니다.

tcp 217 0 xxx.xxx.xxx.xxx:8001 xxx.xxx.xxx.xxx:2143 CLOSE_WAIT
tcp 242 0 xxx.xxx.xxx.xxx:8001 xxx.xxx.xxx.xxx:2185 CLOSE_WAIT
tcp 242 0 xxx.xxx.xxx.xxx:8001 xxx.xxx.xxx.xxx:2314 CLOSE_WAIT
tcp 242 0 xxx.xxx.xxx.xxx:8001 xxx.xxx.xxx.xxx:2252 CLOSE_WAIT
tcp 217 0 xxx.xxx.xxx.xxx:8001 xxx.xxx.xxx.xxx:2124 CLOSE_WAIT
tcp 217 0 xxx.xxx.xxx.xxx:8001 xxx.xxx.xxx.xxx:2191 CLOSE_WAIT

CLOSE_WAIT 은 상대방에서 close를 했고 이쪽에서 close를 하기를 기다리는건데
어찌된게 소켓의 RecvQ에 데이터가 남아 있을수 있는지..의문이 듭니다..

혹시나해서 AcceptThread에서 close하기전에 shutdown을 해도마찬가지네여

stoneshim의 이미지

"AcceptThread" 에서 close() 가 정확히 호출되는지 확인해 보셔야 할것 같습니다.

또, close하는 fd 가 accept 한 fd가 맞는지도 확인해 보셔야 할듯 하구요.

우리 모두 리얼리스트가 되자. 그러나 가슴에 이룰 수 없는 꿈을 가지자

MackTheKnife의 이미지

Thread생성이 안되는것이 문제였읍니다.
AcceptThread를 생성하고나서 AcceptThread가 종료되면 자원반납이
자동으로 되는줄 알았더니 아니였군여..

소스상 pthread_join으로 쓰레드 종료를 체크하기엔 로직이 조금 바뀌어
될것 같아서 안했더니 이런문제가 생겼던것입니다.

pthread_detach로 자원반납을 시키니 해결되었읍니다.
제 무지가 부른 소치네여.

main()
{
    pthread_attr_t attr;
    pthread_attr_init(&attr); 
    pthread_attr_set_detachstate(&attr,PTHREAD_CREATE_DETACHED);
   pthread_create(....,&attr,..)
   pthread_attr_destory(&attr);
}

AccepThread()
{
...
pthread_detach(pthread_self());
}
[/code]

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.