onyxcord 3.2.6 → 3.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a198cb1ead59b05936a681bdf1c83dbf7ffe3b68f223548508e8dde371f2951a
4
- data.tar.gz: 1c81f3befc93b00e0c685e4d3506bbf52fc406bf729f060ad591dfde7818a59c
3
+ metadata.gz: 519bb339e62e93fa61c6a48e004937ad6e7b7e3645abc6be14709edafb4c05cc
4
+ data.tar.gz: efb25e85bdd412727c3f46a69c1b92ebe02a557cb67e878e9040616a25abfa02
5
5
  SHA512:
6
- metadata.gz: 6763d7f434e9dbe46a7838a86df33b5f61de198b200006d442af5b899935f76cfd1afc81ca1d3d80c25f6606f2018a946f4488d4bb3ec254449fe0f3620d90a0
7
- data.tar.gz: 6e4352a1a1b1ba32a770ce2047de68c4b3f677e52ddf9984bd61d17e3d20c560d8f6ce716c8563e51aae0086b980d67a9a31d3830007d7b577dde8353a1d8716
6
+ metadata.gz: 4313a469aa21679b5b6522f954a25a16e9ef07071a31b09c61fdd5a23fe9dc3bd9c8965a0bab94ae758450140501d619acb107ebb31ac4e7f98779745afa37c9
7
+ data.tar.gz: f1accfb656c81f934c96b46af5521c222bc7995eed2445377ef2acf4c868e1ebbcc6840b814b395b0476f0f27d66643c9687899d61ad06c2bbee89c22a8d117a
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnyxCord
4
- VERSION = '3.2.6'
4
+ VERSION = '3.2.8'
5
5
  end
@@ -54,19 +54,36 @@ module OnyxCord
54
54
 
55
55
  module_function
56
56
 
57
- # The shared HTTPX session with persistent connections for the current thread.
57
+ POOL_OPTIONS = {
58
+ max_connections: 50,
59
+ max_connections_per_origin: 20,
60
+ pool_timeout: 10
61
+ }.freeze
62
+
63
+ # The shared HTTPX session with persistent, pooled connections.
58
64
  def session
59
- Thread.current[:onyxcord_http_session] ||= HTTPX.plugin(:persistent)
60
- .plugin(:follow_redirects)
61
- .with(
62
- fallback_protocol: 'http/1.1',
63
- ssl: { alpn_protocols: ['http/1.1'] }
64
- )
65
+ session_mutex.synchronize do
66
+ @session ||= HTTPX.plugin(:persistent)
67
+ .plugin(:follow_redirects)
68
+ .with(
69
+ fallback_protocol: 'http/1.1',
70
+ ssl: { alpn_protocols: ['http/1.1'] },
71
+ pool_options: POOL_OPTIONS
72
+ )
73
+ end
65
74
  end
66
75
 
67
76
  # Reset the HTTP session (useful for tests).
68
77
  def reset!
69
- Thread.current[:onyxcord_http_session] = nil
78
+ session_mutex.synchronize do
79
+ @session&.close if @session.respond_to?(:close)
80
+ ensure
81
+ @session = nil
82
+ end
83
+ end
84
+
85
+ def session_mutex
86
+ @session_mutex ||= Mutex.new
70
87
  end
71
88
 
72
89
  # Perform a raw HTTP request and return a {Response}.
@@ -172,6 +172,7 @@ module OnyxCord::REST
172
172
  retries += 1
173
173
  raise unless retries < max_retries
174
174
 
175
+ ::OnyxCord::Internal::HTTP.reset!
175
176
  OnyxCord::LOGGER.warn("Temporary HTTP failure while sending request (#{e.class}), retrying")
176
177
  OnyxCord::Internal::AsyncRuntime.sleep(retries * 0.5)
177
178
  next
@@ -221,7 +222,11 @@ module OnyxCord::REST
221
222
 
222
223
  err_klass = OnyxCord::Errors.error_class_for(data['code'] || 0)
223
224
  e = err_klass.new(data['message'], data['errors'], status: response.code, headers: response.headers, route: route, body: response.body, response: response)
224
- OnyxCord::LOGGER.error(e.full_message)
225
+ if e.is_a?(OnyxCord::Errors::UnknownMessage)
226
+ OnyxCord::LOGGER.warn('Ignoring stale Discord message reference.')
227
+ else
228
+ OnyxCord::LOGGER.error(e.full_message)
229
+ end
225
230
  raise e
226
231
  end
227
232
  rescue OnyxCord::Errors::NoPermission => e
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onyxcord
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.6
4
+ version: 3.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Silva