Skip to content

socket.gaierror during (re)connection is unhandled #2407

@dgw

Description

@dgw

Description

Running a Sopel instance from my laptop while traveling, the power (and therefore Starlink) at our rental cut out overnight.

Sopel failed to reconnect because of an unhandled error case related to DNS, and quit itself completely.

Reproduction steps

  1. Start Sopel normally and wait for it to connect
  2. Disrupt network connection
    a. If on Wi-Fi, I believe cutting power to the AP would emulate what happened to me

Expected behavior

Sopel should catch any socket.gaierror exception and queue another connection attempt.

Relevant logs

[2023-02-01 04:05:03,340] sopel.cli.run        WARNING  - Disconnected. Reconnecting in 20 seconds...
[2023-02-01 04:05:23,350] sopel.bot            INFO     - Loading plugins...
    <snip, irrelevant noise>
[2023-02-01 04:05:23,463] sopel.bot            INFO     - Plugin loaded: coretasks
[2023-02-01 04:05:23,464] sopel.bot            INFO     - Registered 3 plugins, 0 failed, 55 disabled
[2023-02-01 04:05:39,432] sopel.irc.backends   ERROR    - Unable to connect.
Traceback (most recent call last):
  File "/home/dgw/github/sopel/sopel/irc/backends.py", line 391, in _run_forever
    self._reader, self._writer = await asyncio.open_connection(
  File "/usr/lib/python3.9/asyncio/streams.py", line 52, in open_connection
    transport, _ = await loop.create_connection(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 1017, in create_connection
    infos = await self._ensure_resolved(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 1396, in _ensure_resolved
    return await loop.getaddrinfo(host, port, family=family, type=type,
  File "/usr/lib/python3.9/asyncio/base_events.py", line 856, in getaddrinfo
    return await self.run_in_executor(
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.9/socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution
[2023-02-01 04:05:39,603] sopel.irc.backends   INFO     - Connection backend stopped.
[2023-02-01 04:05:39,603] sopel.bot            INFO     - Shutting down
[2023-02-01 04:05:39,604] sopel.bot            INFO     - Stopping the Job Scheduler.
[2023-02-01 04:05:40,479] sopel.bot            INFO     - Job Scheduler stopped.
[2023-02-01 04:05:40,479] sopel.bot            INFO     - Calling shutdown for 2 plugins.

Notes

Past mentions of gaierror in our issue tracker are mostly about the ip & wikipedia plugins. I'm surprised it never came up for core, outside of one thread about IPv6.

Sopel version

f527b13

Installation method

pip install

Python version

3.9.5

Operating system

Ubuntu 20.04 (WSL 1)

IRCd

No response

Relevant plugins

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThings to squish; generally used for issuesCore/Networking

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions