Skip to content

NickAkhmetov/Implement error handling for API timeouts and improve connection management - #4096

Merged
NickAkhmetov merged 4 commits into
mainfrom
nickakhmetov/api-client-timeouts
Oct 28, 2026
Merged

NickAkhmetov merged 4 commits into
mainfrom
nickakhmetov/api-client-timeouts

Conversation

@NickAkhmetov

@NickAkhmetov NickAkhmetov commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Show a 504 Gateway Timeout page for upstream API timeouts, and 502/503 pages for unreachable/unavailable APIs.
  • Reuse connections to search, entity, and assets APIs to prevent indefinite hanging requests.
  • Add titles for the new 502 and 503 error pages, which otherwise rendered as "Unexpected Error".
  • Bump portal-visualization[full] to >=0.5.14, which adds the shared session and request timeouts this branch depends on.

Design Documentation/Original Tickets

N/A

Testing

Added unit tests, adjusted mocks so that requests are properly scoped by session

Screenshots/Video

Include screenshots or video demonstrating any significant visual or behavioral changes.

Checklist

  • Code follows the project's coding standards
    • Lint checks pass locally
    • New CHANGELOG-your-feature-name-here.md is present in the root directory, describing the change(s) in full sentences.
  • Unit tests covering the new feature have been added
  • All existing tests pass
  • Any relevant documentation in JIRA/Confluence has been updated to reflect the new feature
  • Any new functionalities have appropriate analytics functionalities added

Additional Notes

Depends on x-atlas-consortia/portal-visualization#157, released as portal-visualization 0.5.14.

🤖 Generated with Claude Code

@john-conroy john-conroy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update the error pages?

@NickAkhmetov

NickAkhmetov commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

@john-conroy Yes, good catch. The new 502 and 503 handlers render the React error page, but its title map in pages/Error/utils.ts stopped at 504, so those pages showed "Unexpected Error". 9d78e8d adds "Bad Gateway" and "Service Unavailable" titles. The body text falls through to the generic "If this problem persists, submit a bug report", which fits transient upstream failures, so I left ErrorBody unchanged.

NickAkhmetov and others added 2 commits October 22, 2026 12:05
…gement

- Show a 504 Gateway Timeout page for upstream API timeouts, and 502/503 pages for unreachable/unavailable APIs.
- Reuse connections to search, entity, and assets APIs to prevent indefinite hanging requests.
The new Flask 502 and 503 handlers render the React error page, which only
had titles for 504 and below, so those pages fell through to "Unexpected
Error".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NickAkhmetov
NickAkhmetov marked this pull request as ready for review October 22, 2026 16:06
@NickAkhmetov
NickAkhmetov force-pushed the nickakhmetov/api-client-timeouts branch from 9d78e8d to 1b79924 Compare October 22, 2026 16:06
john-conroy
john-conroy previously approved these changes Oct 27, 2026

@john-conroy john-conroy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my previous comments.

Not directly impacted by this PR, but _get_sitemap_entities_cached and _get_publication_data_types_and_organs will cache an errored result. Both catch the exception and return an empty value ([] and ([], [])), and @cache (functools.cache) stores that like a normal result.

The login, logout and group-lookup calls to Globus now pass
EXTERNAL_REQUEST_TIMEOUT, so a hung call can't hold a gthread worker
indefinitely. test_503_html_page covers the new service_unavailable handler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NickAkhmetov

Copy link
Copy Markdown
Collaborator Author

Good catch. This is fixed in #4107: _get_sitemap_entities_cached and _get_publication_data_types_and_organs now raise instead of returning an empty value, and their callers catch, so a failure is never memoized. The sitemap one is now an lru_cache keyed on the hour bucket, behind a try/except wrapper (_get_sitemap_entities). The template-keys lookup got the same treatment. All three also fetch with use_groups_token=False, since the results are shared across visitors.

@NickAkhmetov
NickAkhmetov merged commit fd19705 into main Oct 28, 2026
7 of 8 checks passed
@NickAkhmetov
NickAkhmetov deleted the nickakhmetov/api-client-timeouts branch October 28, 2026 12:17
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.

2 participants