Skip to content

Commit

Permalink
[FIX] Changed sqlite3 to use autocommit mode which fixed random errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tayler6000 committed Dec 30, 2023
1 parent 0902757 commit a215093
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions pyVoIP/sock/sock.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ def _udp_recv(self, nbytes: int, timeout=0, peak=False) -> bytes:
conn.close()
return row["msg"].encode("utf8")
try:
self.sock.buffer.commit()
conn.execute('DELETE FROM "msgs" WHERE "id" = ?', (row["id"],))
self.sock.buffer.commit()
except sqlite3.OperationalError:
pass
conn.close()
Expand Down Expand Up @@ -184,7 +182,9 @@ def __init__(
self.s = self.server_context.wrap_socket(self.s, server_side=True)

self.buffer = sqlite3.connect(
pyVoIP.SIP_STATE_DB_LOCATION, check_same_thread=False
pyVoIP.SIP_STATE_DB_LOCATION,
isolation_level=None,
check_same_thread=False,
)
"""
RFC 3261 Section 12, Paragraph 2 states:
Expand Down Expand Up @@ -225,10 +225,6 @@ def __init__(
PRIMARY KEY("call_id", "local_tag", "remote_tag")
);"""
)
try:
self.buffer.commit()
except sqlite3.OperationalError:
pass
conn.close()
self.conns_lock = threading.Lock()
self.conns: List[VoIPConnection] = []
Expand Down Expand Up @@ -300,7 +296,6 @@ def __register_connection(self, connection: VoIPConnection) -> int:
conn_id,
),
)
self.buffer.commit()
except sqlite3.IntegrityError as e:
e.add_note(
"Error is from registering connection for message: "
Expand Down Expand Up @@ -348,7 +343,6 @@ def deregister_connection(self, connection: VoIPConnection) -> None:
conn.execute(
'DELETE FROM "listening" WHERE "connection" = ?', (conn_id,)
)
self.buffer.commit()
except sqlite3.OperationalError:
pass
finally:
Expand Down Expand Up @@ -446,10 +440,6 @@ def _handle_incoming_message(
+ "VALUES (?, ?, ?, ?)",
(call_id, local_tag, remote_tag, raw_message),
)
try:
self.buffer.commit()
except sqlite3.OperationalError:
pass
conn.close()
if conn_id:
self.sip.handle_new_connection(self.conns[conn_id])
Expand Down

0 comments on commit a215093

Please sign in to comment.