NFIBrokerage / spear

A sharp EventStoreDB v20+ client backed by Mint :yum:

Home Page:https://hex.pm/packages/spear

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

catch subscription drops due to stream deletions

the-mikedavis opened this issue · comments

just saw this testing out persistent subscriptions: it looks like it terminates the grpc request if you delete the stream while subscribed

should test it out and come up with a solution for psubs & regular subs

I suspect that this is done in the handle_responses/2 function in the connection

will have to detect that the request is a subscription and instead of GenServer.call/3ing it with the grpc response, we format and send a {:eos, :deleted}

suspect that the fix will be the same between regular and persistent subscriptions

actually a quick muck around in IEx shows that a stream being deleted doesn't interrupt a subscription

appears as though the subscription just stays subscribed and if new events get written, those go to the subscriber process

if we do a tombstone on a subscription, though, it gets a $streamDeleted type event

seems like there could be some value in giving an {:eos, :deleted} instead of that event but it's pretty easy to match on anyways so I wouldn't feel terrible about leaving that as a user-space concern

stacktrace for a deletion to a psub while a subscriber is connected

15:33:36.527 [error] GenServer #PID<0.286.0> terminating
** (FunctionClauseError) no function clause matching in :gen_server.reply/2
    (stdlib 3.14) gen_server.erl:293: :gen_server.reply(nil, {:ok, %Spear.Connection.Response{data: "", headers: [{"date", "Fri, 23 Apr 2021 15:33:22 GMT"}, {"content-type", "application/grpc"}, {"server", "Kestrel"}, {"grpc-message", "Subscription group asdf on stream asdf was dropped."}, {"grpc-status", "1"}, {"exception", "persistent-subscription-dropped"}, {"stream-name", "asdf"}, {"group-name", "asdf"}], status: 200, type: {:spear_proto_persistent, :"event_store.client.persistent_subscriptions.ReadResp"}}})
    (spear 0.0.0) lib/spear/connection.ex:397: Spear.Connection.process_response/2
    (elixir 1.12.0-rc.0) lib/enum.ex:2358: Enum."-reduce/3-lists^foldl/2-0-"/3
    (spear 0.0.0) lib/spear/connection.ex:358: Spear.Connection.handle_responses/2
    (spear 0.0.0) lib/spear/connection.ex:336: Spear.Connection.handle_info/2