소켓 close시 Block되는 현상...

isinji의 이미지

일:다수 형태의 socket 프로그램입니다. poll을 사용하여 클라이언트를 처리 중인데 client의 종료시 간혹 서버프로그램에서 이상한 점이 발견됩니다.

poll descriptor set을 검사할 때 POLLHUP이 발생하면 해당 descriptor를 close하고 descriptor를 -1 로 셋합니다. 그런데 간혹 close가 바로 리턴되지 않고 약 2초정도 block 후 return되는 현상일 발생합니다. 현재는 close 전에 alarm(1)을 셋하여 close가 1초 이상 지연되지 않도록 되어있습니다.

따라서 close가 1초 이상 지연될 경우 interrupt되어 해당 descriptor가 poll의 descriptor set에서 빠지지 않으므로 다음 번 poll()에서도 해당 event를 받게 되더군요. 1초 이상 close에서 지연되면 업무에 미치는 영향이 커서 어쩔 수 없이 이렇게 사용하고 있다고 합니다.

혹시 이런 현상을 경험한 분이 계시다면 조언 부탁드립니다.

환경은 HP Alpha Server, Tru64 UNIX Version 5.1입니다.

bugiii의 이미지

종료 시점의 스트림내의 내용이 중요하지 않다면 소켓 옵션 SO_LINGER 을 사용해서 강제종료를 하시는 것은 어떨지요?
alarm을 썼다고 하셨으니... 문제되지 않을 듯 합니다만...

김성진의 이미지

close시에 인자가 -1 (0xfffffff) 여서 문제가 생겼을 가능성이

높습니다.

portability 를 고려하신다면, 가능하면 화일 디스크립터값 자체에 대해서는

close이전에 reset하지 않는게 좋을 듯 합니다.

김성진 드림

PS:유사한 경험이 있었습니다.

고도의 추상화, 극도의 구체화, 에디슨을 그리워하다.

bugiii의 이미지

그런 경우였다면 close 의 리턴값 조사만으로도 충분할텐데요...
디버깅용 책들을 보면 핸들을 닫는 함수의 리턴값 조사도 아주 중요하다고 합니다.

isinji의 이미지

원인은 찾아냈습니다.

socket 옵션에 SO_LINGER를 주었더군요... linger를 ON시켜놓은 상태에서 서버측 send buffer에 데이터가 남아있었던 것 같습니다...

답변 주신 모든 분들께 감사드립니다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.