Skip to content

IORef based Socket is unsafe #335

@winterland1989

Description

@winterland1989

Peek through recently network's code, the new IORef CInt based Socket seems to still have previous discussed fd-reuse race condiftion:

  1. Thread A acquires a Socket 's fd by fdSocket, when it's about to do some operations, the scheduler decide to pause thread A.

  2. Thread B close the socket, rewrite the Socket 's IORef 's content.

  3. Thread C open a new socket, unfortunately got the same fd number thread A is holding now.

  4. When thread A is resumed, it's unaware of thread B and thread C 's behavior, thus the following operations will performed successfully, but on a wrong fd.

Maybe it's necessary to add some docs on close ?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions