Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webhook: fix error on reconnect #72

Merged
merged 1 commit into from
Oct 24, 2020

Conversation

HumorBaby
Copy link
Contributor

@HumorBaby HumorBaby commented Aug 8, 2020

The bot runs plugin shutdowns on disconnect from the IRC server. While
this method stops serving requests it doesn't actually close the socket;
thus, the "restarted" webserver cannot bind to the same host/port in order
to listen+serve requests. This results in a OSError: [Errno 98] Address already in use. The server needs to be closed after shutdown.

edit: As of this commit, the fix is valid for all supported Python >=2.7,>=3.5.

The bot runs plugin `shutdown`s on disconnect from the IRC server. While
this method stops serving requests it doesn't actually close the socket;
the restarted webserver cannot then bind to the same host/port in order
to listen+serve requests.  This results in a `OSError: [Errno 98]
Address already in use`. To avoid this, the server needs to be closed
after `shutdown`.

As of this commit, the fix is valid for all Python>=2.7,>=3.5.
@HumorBaby
Copy link
Contributor Author

FYI, you can emulate disconnects like those leading to #70 by forwarding a local port to an IRC server (or bouncer). If you connect via SSL, you will likely have to set verify_ssl = false in the bot config during testing.

Example:

## Set the bot to connect to localhost:6665
## (the bot will start the shutdown-wait-reconnect cycle each time you stop socat)
$ socat TCP4-LISTEN:6665,fork,reuseaddr TCP4:chat.freenode.net:6665
^C
$ socat TCP4-LISTEN:6665,fork,reuseaddr TCP4:chat.freenode.net:6665
^C

@dgw
Copy link
Member

dgw commented Aug 8, 2020

Why Python >=3.5 and not >=3.3? While not a hard requirement, it's ideal for a Sopel 7 plugin to support all Python versions that Sopel itself runs on—and until Sopel 8.0, that's 2.7.x and 3.3+.

(Before writing that massive comment on #70, I swear I had two questions about this PR, but I can only think of the one now. Sorry in advance if I come back and double-post because I suddenly remembered what question 2 was going to be! 😅)

@HumorBaby
Copy link
Contributor Author

HumorBaby commented Aug 8, 2020 via email

@dgw dgw added this to the 0.4.0 milestone Oct 19, 2020
@dgw dgw added the bugfix label Oct 19, 2020
@dgw dgw linked an issue Oct 19, 2020 that may be closed by this pull request
@dgw
Copy link
Member

dgw commented Oct 19, 2020

Totally missed labeling/milestoning this before. I think it's about time to push for 0.4.0 soon, with all its nice little tweaks.

@dgw dgw changed the base branch from 0.3.x to master October 24, 2020 07:29
@dgw dgw merged commit b75440d into sopel-irc:master Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: "Address already in use" when Sopel reconnects with webhooks enabled
2 participants