Skip to content

Commit 783018c

Browse files
authored
fix: MacOS keepalive setting (#119)
1 parent 9aaa8c9 commit 783018c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/firebolt/async_db/connection.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

3+
import socket
34
from json import JSONDecodeError
4-
from socket import IPPROTO_TCP, SO_KEEPALIVE, SOL_SOCKET, TCP_KEEPIDLE
55
from types import TracebackType
66
from typing import Callable, List, Optional, Type
77

@@ -157,11 +157,17 @@ async def connect_tcp(
157157
)
158158
# Enable keepalive
159159
stream.get_extra_info("socket").setsockopt(
160-
SOL_SOCKET, SO_KEEPALIVE, KEEPALIVE_FLAG
160+
socket.SOL_SOCKET, socket.SO_KEEPALIVE, KEEPALIVE_FLAG
161161
)
162+
# MacOS does not have TCP_KEEPIDLE
163+
if hasattr(socket, "TCP_KEEPIDLE"):
164+
keepidle = socket.TCP_KEEPIDLE
165+
else:
166+
keepidle = 0x10 # TCP_KEEPALIVE on mac
167+
162168
# Set keepalive to 60 seconds
163169
stream.get_extra_info("socket").setsockopt(
164-
IPPROTO_TCP, TCP_KEEPIDLE, KEEPIDLE_RATE
170+
socket.IPPROTO_TCP, keepidle, KEEPIDLE_RATE
165171
)
166172
return stream
167173

0 commit comments

Comments
 (0)