Skip to content

fix(Plugs.RecentlyVisited): handle task timeout#3303

Open
thecristen wants to merge 3 commits into
mainfrom
cbj/recently-visited-and-improved
Open

fix(Plugs.RecentlyVisited): handle task timeout#3303
thecristen wants to merge 3 commits into
mainfrom
cbj/recently-visited-and-improved

Conversation

@thecristen

@thecristen thecristen commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Scope

(from the homepage) MBTA-DOTCOM-JN
(from the mode pages, e.g. /schedules/bus) MBTA-DOTCOM-JM

Uncaught exit - {:timeout, {Task.Supervised, :stream, [5000]}}
    lib/task/supervised.ex:349: Elixir.Task.Supervised.Task.Supervised.stream_reduce/7
    lib/enum.ex:4570: Elixir.Enum.Enum.reduce/3
    lib/dotcom_web/plugs/recently_visited.ex:33: Elixir.DotcomWeb.Plugs.RecentlyVisited.DotcomWeb.Plugs.RecentlyVisited.assign_recently_visited/2
    lib/dotcom_web/controllers/mode_controller.ex:1: Elixir.DotcomWeb.ModeController.DotcomWeb.ModeController.phoenix_controller_pipeline/2
    lib/phoenix/router.ex:416: Elixir.Phoenix.Router.Phoenix.Router.__call__/5
    deps/plug/lib/plug/error_handler.ex:80: Elixir.DotcomWeb.Router.DotcomWeb.Router.call/2
    lib/dotcom_web/endpoint.ex:1: Elixir.DotcomWeb.Endpoint.DotcomWeb.Endpoint.plug_builder_call/2
    lib/dotcom_web/endpoint.ex:1: Elixir.DotcomWeb.Endpoint.DotcomWeb.Endpoint."call (overridable 3)"/2

Implementation

The Task.async_stream/3 call wasn't handling the timeout! So now we can handle the timeout, by specifying on_timeout. (We don't do anything special with the result - if we can't fetch the route we'll ignore it.)

I also adjusted the call in the ModeController: it turns out we were calling the plug on each mode, but we don't even show Recently Visited routes on those pages. So now it's only run on the /schedules/ page.


@thecristen thecristen requested a review from a team as a code owner June 30, 2026 18:13
@thecristen thecristen requested a review from jlucytan June 30, 2026 18:13
@thecristen thecristen enabled auto-merge (squash) June 30, 2026 18:51
@thecristen thecristen force-pushed the cbj/recently-visited-and-improved branch from 0bf14bc to def601e Compare July 1, 2026 19:04
@thecristen

thecristen commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

Updated with another commit (refactor(Plugs.RecentlyVisited): use Stream) which tackles 📈 Speed up Recently-Visited call on the homepage

edit: forgot the flamegraphs

Before After
flame_on (recently visited before) flame_on (recently visited after)

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.

1 participant