Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Experimental Unix socket support #15353

Merged
merged 20 commits into from Apr 3, 2023
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
906acaf
Add IReactorUNIX to ISynapseReactor type hint.
realtyem Mar 27, 2023
aac7fac
Create listen_unix().
realtyem Mar 28, 2023
9abd099
Create UnixListenerConfig and wire it up.
realtyem Mar 28, 2023
43a6ee9
Refactor SynapseRequest to handle logging correctly when using a unix…
realtyem Mar 29, 2023
7b93a29
Make the 'Synapse now listening on Unix socket' log line a little pre…
realtyem Mar 29, 2023
3267581
No silent failures on generic workers when trying to use a unix socke…
realtyem Mar 29, 2023
1e0452f
Inline variables in app/_base.py
realtyem Mar 29, 2023
c0eb5b3
Update docstring for listen_unix() to remove reference to a hardcoded…
realtyem Mar 29, 2023
9fdbb5d
Disallow both a unix socket and a ip/port combo on the same listener …
realtyem Mar 29, 2023
67eecf0
Linting
realtyem Mar 29, 2023
c74ad1d
Changelog
realtyem Mar 29, 2023
2309543
Merge branch 'develop' into exp/unix-reactor
realtyem Mar 29, 2023
3703cd0
review: simplify how listen_unix returns(and get rid of a type: ignore)
realtyem Mar 30, 2023
8876780
review: fix typo from ConfigError in app/homeserver.py
realtyem Mar 30, 2023
d6b88f3
review: roll conditional for http_options.tag into get_site_tag() hel…
realtyem Mar 30, 2023
2acf0a6
review: enhance the conditionals for checking if a port or path is va…
realtyem Mar 30, 2023
2a99e49
review: Try updating comment in get_client_ip_if_available to clarify…
realtyem Mar 31, 2023
547ff5f
Pretty up how 'Synapse now listening on Unix Socket' looks by decodin…
realtyem Mar 31, 2023
d1742a4
review: In parse_listener_def(), raise ConfigError if neither socket_…
realtyem Apr 1, 2023
cfdc5ac
Merge branch 'develop' into exp/unix-reactor
realtyem Apr 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 32 additions & 1 deletion synapse/app/_base.py
Expand Up @@ -41,7 +41,12 @@

import twisted
from twisted.internet import defer, error, reactor as _reactor
from twisted.internet.interfaces import IOpenSSLContextFactory, IReactorSSL, IReactorTCP
from twisted.internet.interfaces import (
IOpenSSLContextFactory,
IReactorSSL,
IReactorTCP,
IReactorUNIX,
)
from twisted.internet.protocol import ServerFactory
from twisted.internet.tcp import Port
from twisted.logger import LoggingFile, LogLevel
Expand Down Expand Up @@ -351,6 +356,32 @@ def listen_tcp(
return r # type: ignore[return-value]


def listen_unix(
path: str,
mode: int,
factory: ServerFactory,
reactor: IReactorUNIX = reactor,
backlog: int = 50,
) -> List[Port]:
"""
Create a UNIX socket for a given path with a permission of 0o666(that's octal)

Returns:
list of twisted.internet.tcp.Port listening for TCP connections
"""
r = []
wantPID = True

try:
r.append(reactor.listenUNIX(path, factory, backlog, mode, wantPID))
except error.CannotListenError as e:
raise e
realtyem marked this conversation as resolved.
Show resolved Hide resolved

# IReactorUNIX returns an object implementing IListeningPort from listenUNIX,
# but we know it will be a Port instance.
return r # type: ignore[return-value]


def listen_http(
listener_config: ListenerConfig,
root_resource: Resource,
Expand Down