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

Add exit handler which fires when Touch Portal exits with the plugin …#10

Open
jaybz wants to merge 1 commit intotlewis17:developfrom
jaybz:exithandler
Open

Add exit handler which fires when Touch Portal exits with the plugin …#10
jaybz wants to merge 1 commit intotlewis17:developfrom
jaybz:exithandler

Conversation

@jaybz
Copy link
Contributor

@jaybz jaybz commented Apr 25, 2021

This adds an exit handler which fires when Touch Portal exits with the plugin still running so that the plugin can quit gracefully.

This fixes an issue where the main plugin loop is not able to detect that Touch Portal has exited. It still requires the exit handler to terminate the plugin process, but otherwise, I haven't found a way to detect that the socket to Touch Portal is already closed.

I've used a separate PR for this so that it can be reviewed separately from the PR for API 3 additions. Hopefully, this doesn't cause any merge issues if/when both PRs gets merged.

@jaybz
Copy link
Contributor Author

jaybz commented Apr 29, 2021

I found an issue with this that will cause the plugin to die prematurely in certain cases. I'm looking for a solution for the issue.

@jaybz
Copy link
Contributor Author

jaybz commented May 9, 2021

Turns out the issue isn't related to the code in this PR. The socket disconnects spontaneously regardless but I can't pin down what is causing it yet. Without knowing the cause, it may be possible to "fix" the issue by reconnecting the socket.

@oddbear
Copy link

oddbear commented May 9, 2021

On issue I had (that I have raised an issue for) was with the UnboundedChannelOptions and changing the AllowSynchronousContinuations you can try that. This made my plugin at that time fail at random times when sending and receiving messages.

However if the problem came out after TouchPortal 2.3, there should not be many changes, but now the default is message type is utf8 without BOM. With BOM is default in .Net and will make issues (at least when I tried).

I have not seen this issue you describe in my plugins, using "pure .Net sockets".

@jaybz
Copy link
Contributor Author

jaybz commented May 9, 2021

On issue I had (that I have raised an issue for) was with the UnboundedChannelOptions and changing the AllowSynchronousContinuations you can try that. This made my plugin at that time fail at random times when sending and receiving messages.

However if the problem came out after TouchPortal 2.3, there should not be many changes, but now the default is message type is utf8 without BOM. With BOM is default in .Net and will make issues (at least when I tried).

I have not seen this issue you describe in my plugins, using "pure .Net sockets".

I looked at the issue you raised. It doesn't seem similar to the disconnection issue, but I'll try it anyway. In any case, TCP connections should theoretically be treated as potentially unstable and disconnects should at least be expected and handled appropriately. In this case it looks like a reconnect might be the ideal behavior instead of just exiting. It's rather weird though that a connection to localhost would randomly disconnect. I'm beginning to think I have something else running that's causing this, but I have no idea what.

@oddbear
Copy link

oddbear commented May 9, 2021

As long as it does not go against localhost, I guess reconnect logic would make sense.
Have never had any issues with this locally, and cannot se that any of the other SDKs have implemented any reconnect logic either.

Might be that something in a dependency messes with something like the ServicePointManager.SetTcpKeepAlive maybe?
But I just throwing out stuff here now. :P
How this keep alive stuff works, I am not sure about. I cannot se that any ping/pong messages pops up in Wireshark etc. (like is common on some protocols).

@jaybz
Copy link
Contributor Author

jaybz commented May 28, 2021

Turns out the socket wasn't disconnecting on its own. Something else was generating an exception in my plugin and it was getting hidden by the indiscriminate exception catching in this API. This ends up causing an unnecessary disconnect of the socket. I haven't tracked down exactly where this is happening in the code, but this PR is completely unrelated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants