Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • Synchronet Synchronet
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 226
    • Issues 226
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar

This GitLab instance has migrated as of Nov-5-2022 to a new server: hardware, OS, SSH key

The v3.20a development branch has now been merged to the master branch. Sysops upgrading from earlier versions must run 'jsexec update'

  • MainMain
  • SynchronetSynchronet
  • Merge requests
  • !212

syncterm: use shutdown() ahead of close() for rlogin/ssh

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed anonymouspage requested to merge anonymouspage/sbbs:use-shutdown-before-close into master Oct 19, 2022
  • Overview 1
  • Commits 1
  • Pipelines 2
  • Changes 2

Using only close() on a socket has a few issues:

(1) poll is not required to wake on such events leading to hangs if infinite timeouts are used.

 This can be observed in macOS:

 (a) syncterm -iC
 (b) connect via telnet to some system
 (c) use the menu to disconnect from the system

 Note: socket must be idle to reproduce.

(2) If a blocked recv/send receives an error in response to a close from another thread, the context of the socket has been lost: the descriptor is free to be reallocated under the thread performing I/O by the system. Any retry logic that may be written in response to the error condition could lead to operations being performed on a valid but incorrect resource.

(3) Processes that inherited the socket via fork() will still have a valid descriptor to the socket. i.e., the socket does not globally shutdown via a call to close(); however, shutdown() acts on the connection by triggering a TCP FIN. This will lead to the actual shutdown of the socket by the remote connection as well.

Solution:

Use shutdown() ahead of close(). This will initiate a proper shutdown sequence on the socket while leaving the descriptor open. poll() will wake, and a subsequent read or write will yield the desired EOF/EPIPE.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: use-shutdown-before-close