Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.
This repository was archived by the owner on May 31, 2021. It is now read-only.

Please tell me about thread policy in this library #57

@omochi

Description

@omochi

I have some questions about thread policy.

question 1

What is purpose of this code ?

// Makes sure we aren't in an event loop when we try to reconnect in the future
DispatchQueue.main.async {
do {
try ws.wait()
} catch {
Sword.log(.error, .gatewayConnectFailure(error.localizedDescription))
}
}
}

ws.wait() blocks thread execution until this gateway connection close.
So this code stops main thread.
It blocks my application logic.

And if multiples Shard objects exists, first one blocks main thread.
So same tasks from consequence other object will not run.
If later shard close earlier than early shard, later shard task will not finish.

question 2

Simultaneous access from NIO thread and heartbeatQueue are safe ?
I don't think so...

Shard.heartbeat method called in heartbeatQueue.
It touches session, ackMissed.
session property also touched from closure in GatewayHandler.conenct method.
It should be from NIO thread.
So these access may occur race condition.

Static object Sword.encoder also touched from these threads in Sword.send method.

question 3

What thread is intended to call GatewayHandler.connect and disconnect.
These method looks public interface for user.
Can user call them from main thread?
disconnect method called from reconnect method.
reconnect method called from heatbeat, handleClose, handlePayload.
So disconnect called from NIO thread, heartbeatQueue, and main.
I think it occurs race condition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions