Skip to content
Snippets Groups Projects
Verified Commit b1706a06 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

api: Add lock on API requests

Should hopefully avoid some multi-threading issues
parent a5505339
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
- Adds preliminary support for the Matrix v1.1 client/v3 API
- Adds some support for knocking rooms
- Adds locks on API requests to avoid threading issues
## 2.4.0 - 2021-07-19
......
......@@ -64,6 +64,7 @@ module MatrixSdk
@global_headers.merge!(params.fetch(:global_headers)) if params.key? :global_headers
@synapse = params.fetch(:synapse, true)
@http = nil
@http_lock = Mutex.new
([params.fetch(:protocols, [:CS])].flatten - protocols).each do |proto|
self.class.include MatrixSdk::Protocols.const_get(proto)
......@@ -281,7 +282,9 @@ module MatrixSdk
req_obj = construct_request(url: url, method: method, **options)
print_http(req_obj, id: req_id)
begin
response = nil
duration = nil
@http_lock.synchronize do
dur_start = Time.now
response = http.request req_obj
dur_end = Time.now
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment