Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Net::ReadTimeout (MAYBE-MARKETING-3Q) #267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

revise-dev[bot]
Copy link
Contributor

@revise-dev revise-dev bot commented Feb 18, 2025

The Net::ReadTimeout error occurs when an HTTP request takes too long to complete, causing the connection to time out. In this case, the requests to the Synth Finance API are timing out, likely due to network latency or server response delays.

The original code made HTTP requests without specifying timeout parameters, relying on Ruby's default timeout settings. This can lead to requests hanging indefinitely in poor network conditions or when the API is experiencing delays.

The fix adds timeout parameters to all HTTP requests in the Provider::Synth class, not just the fetch_exchange_rates method. This is important because:

  1. All HTTP methods should have consistent timeout behavior
  2. We want to prevent timeouts across all API endpoints
  3. The error could manifest in any of the API calls

We're setting a 15-second timeout which provides:

  • Enough time for the API to respond under normal conditions
  • Protection against indefinite hanging
  • A reasonable wait time for users

We're also adding the timeout parameter to all HTTParty.get calls in the class to ensure consistent behavior across all API endpoints. This includes:

  • fetch_stock_prices
  • fetch_exchange_rate
  • fetch_exchange_rates
  • fetch_insider_trades
  • fetch_recent_insider_trades

The 15-second timeout is a balanced choice that:

  • Is long enough to allow for normal API response times
  • Is short enough to prevent poor user experience
  • Allows for some network latency
  • Is consistent with common API timeout practices
Error Details

Summary:

Net::ReadTimeout: Net::ReadTimeout with # (Net::ReadTimeout)

Stacktrace:

net/protocol.rb:229
net/protocol.rb:199
net/protocol.rb:209
net/http/response.rb:158
net/http/response.rb:147
net/http.rb:2420
net/http.rb:2411
net/http.rb:2411
net/http.rb:2384
sentry/net/http.rb:44
sentry/hub.rb:115
sentry/span.rb:237
sentry/hub.rb:113
sentry-ruby.rb:507
sentry/net/http.rb:37
net/http.rb:2377
net/http.rb:1632
net/http.rb:2375
sentry/net/http.rb:34
httparty/request.rb:156
httparty.rb:611
httparty.rb:521
httparty.rb:644
app/models/provider/synth.rb:174
app/models/provider/synth.rb:60
app/presenters/tool/presenter/exchange_rate_calculator.rb:52
action_view/base.rb:281
action_view/base.rb:281
action_view/template.rb:284
active_support/notifications.rb:210
active_support/notifications/instrumenter.rb:58
sentry/rails/tracing.rb:56
active_support/notifications.rb:210
action_view/template.rb:583
action_view/template.rb:272
action_view/renderer/partial_renderer.rb:252
active_support/notifications.rb:210
active_support/notifications/instrumenter.rb:58
sentry/rails/tracing.rb:56
active_support/notifications.rb:210
action_view/renderer/partial_renderer.rb:246
action_view/renderer/partial_renderer.rb:237
action_view/renderer/renderer.rb:78
action_view/renderer/renderer.rb:49
action_view/helpers/rendering_helper.rb:152
action_view/helpers/capture_helper.rb:50
action_view/buffers.rb:75
action_view/helpers/capture_helper.rb:50
action_view/helpers/tag_helper.rb:230
action_view/helpers/tag_helper.rb:329
/home/deploy/maybe-marketing-prod/shared/bundle/ruby/3.4.0/gems/turbo-rails-2.0.11/app/helpers/turbo/frames_helper.rb:42
action_view/base.rb:281
action_view/base.rb:281
action_view/template.rb:284
active_support/notifications.rb:210
active_support/notifications/instrumenter.rb:58
sentry/rails/tracing.rb:56
active_support/notifications.rb:210
action_view/template.rb:583
action_view/template.rb:272
action_view/renderer/partial_renderer.rb:252
active_support/notifications.rb:210
active_support/notifications/instrumenter.rb:58
sentry/rails/tracing.rb:56
active_support/notifications.rb:210
action_view/renderer/partial_renderer.rb:246
action_view/renderer/partial_renderer.rb:237
action_view/renderer/renderer.rb:78
action_view/renderer/renderer.rb:49
action_view/helpers/rendering_helper.rb:152
action_view/helpers/capture_helper.rb:50
action_view/buffers.rb:75
action_view/helpers/capture_helper.rb:50
action_view/helpers/capture_helper.rb:176
action_view/base.rb:281
action_view/base.rb:281
action_view/template.rb:284
active_support/notifications.rb:210
active_support/notifications/instrumenter.rb:58
sentry/rails/tracing.rb:56
active_support/notifications.rb:210
action_view/template.rb:583
action_view/template.rb:272
action_view/renderer/template_renderer.rb:66
active_support/notifications.rb:210
active_support/notifications/instrumenter.rb:58
sentry/rails/tracing.rb:56
active_support/notifications.rb:210
action_view/renderer/template_renderer.rb:60
action_view/renderer/template_renderer.rb:76
active_support/notifications.rb:210
active_support/notifications/instrumenter.rb:58
sentry/rails/tracing.rb:56
active_support/notifications.rb:210
action_view/renderer/template_renderer.rb:75
action_view/renderer/template_renderer.rb:59
action_view/renderer/template_renderer.rb:11
action_view/renderer/renderer.rb:58
action_view/renderer/renderer.rb:31
action_view/rendering.rb:136
action_view/base.rb:308
action_view/rendering.rb:135
action_controller/metal/streaming.rb:179
action_view/rendering.rb:122
action_controller/metal/rendering.rb:186
action_controller/metal/renderers.rb:140
abstract_controller/rendering.rb:28
action_controller/metal/rendering.rb:167
action_controller/metal/instrumentation.rb:31
active_support/benchmark.rb:17
action_controller/metal/instrumentation.rb:31
action_controller/metal/instrumentation.rb:100
active_record/railties/controller_runtime.rb:46
action_controller/metal/instrumentation.rb:30
meta_tags/controller_helper.rb:22
action_controller/metal/implicit_render.rb:39
action_controller/metal/basic_implicit_render.rb:9
abstract_controller/base.rb:226
action_controller/metal/rendering.rb:193
abstract_controller/callbacks.rb:261
active_support/callbacks.rb:120
turbo-rails.rb:24
/home/deploy/maybe-marketing-prod/shared/bundle/ruby/3.4.0/gems/turbo-rails-2.0.11/app/controllers/concerns/turbo/request_id_tracking.rb:10
active_support/callbacks.rb:129
action_text/rendering.rb:25
action_text/engine.rb:71
active_support/callbacks.rb:129
active_support/callbacks.rb:129
sentry/rails/controller_transaction.rb:21
sentry/hub.rb:115
sentry/span.rb:237
sentry/hub.rb:113
sentry-ruby.rb:507
sentry/rails/controller_transaction.rb:18
active_support/callbacks.rb:129
active_support/callbacks.rb:140
abstract_controller/callbacks.rb:260
action_controller/metal/rescue.rb:27
action_controller/metal/instrumentation.rb:76
active_support/notifications.rb:210
active_support/notifications/instrumenter.rb:58
sentry/rails/tracing.rb:56
active_support/notifications.rb:210
action_controller/metal/instrumentation.rb:75
action_controller/metal/params_wrapper.rb:259
active_record/railties/controller_runtime.rb:39
abstract_controller/base.rb:163
action_view/rendering.rb:40
action_controller/metal.rb:252
action_controller/metal.rb:335
action_dispatch/routing/route_set.rb:67
action_dispatch/routing/route_set.rb:50
action_dispatch/journey/router.rb:53
action_dispatch/journey/router.rb:133
action_dispatch/journey/router.rb:126
action_dispatch/journey/router.rb:126
action_dispatch/journey/router.rb:34
action_dispatch/routing/route_set.rb:908
logtail-rails/error_event.rb:24
logtail-rack/http_events.rb:213
logtail-rack/user_context.rb:74
logtail-rails/session_context.rb:16
logtail-rack/http_context.rb:23
logtail/current_context.rb:120
logtail/current_context.rb:44
logtail-rack/http_context.rb:22
rack/static.rb:161
rack/tempfile_reaper.rb:20
rack/etag.rb:29
rack/conditional_get.rb:31
rack/head.rb:15
action_dispatch/http/permissions_policy.rb:38
action_dispatch/http/content_security_policy.rb:38
rack/session/abstract/id.rb:274
rack/session/abstract/id.rb:268
action_dispatch/middleware/cookies.rb:706
action_dispatch/middleware/callbacks.rb:31
active_support/callbacks.rb:100
action_dispatch/middleware/callbacks.rb:30
sentry/rails/rescued_exception_interceptor.rb:14
action_dispatch/middleware/debug_exceptions.rb:31
sentry/rack/capture_exceptions.rb:30
sentry/hub.rb:269
sentry-ruby.rb:420
sentry/rack/capture_exceptions.rb:21
sentry/hub.rb:59
sentry-ruby.rb:400
sentry/rack/capture_exceptions.rb:20
action_dispatch/middleware/show_exceptions.rb:32
rails/rack/logger.rb:41
rails/rack/logger.rb:29
action_dispatch/middleware/remote_ip.rb:96
action_dispatch/middleware/request_id.rb:34
rack/method_override.rb:28
rack/runtime.rb:24
active_support/cache/strategy/local_cache_middleware.rb:29
action_dispatch/middleware/executor.rb:16
action_dispatch/middleware/static.rb:27
rack/sendfile.rb:114
action_dispatch/middleware/ssl.rb:92
rails/engine.rb:535
puma/configuration.rb:279
puma/request.rb:99
puma/thread_pool.rb:390
puma/request.rb:98
puma/server.rb:472
puma/server.rb:254
puma/thread_pool.rb:167

Tip

You can make revisions or ask questions of Revise.dev by using /revise in any comment or review!

  • /revise Add a comment above the method to explain why we're making this change.
  • /revise Why did you choose to make this change specifically?

Important

If something doesn’t look right, click to retry this interaction.

Quick links: View in SentryView in Revise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants