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

Realtime dropping connection intermittently #21

Closed
awalias opened this issue Feb 25, 2020 · 5 comments
Closed

Realtime dropping connection intermittently #21

awalias opened this issue Feb 25, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@awalias
Copy link
Member

awalias commented Feb 25, 2020

Running the test script in supabase-js https://github.com/supabase/supabase/blob/master/libraries/supabase-js/test/integration/testRealtime.js

I get intermittent Network timeout. Still waiting... and REALTIME DISCONNECTED errors

When I inspect the server logs, there are a couple of errors logged:

127.0.0.1 - - [25/Feb/2020:17:26:17 +0000] "POST /messages HTTP/1.1" 201 - "" ""
17:26:18.082 [info] "realtime:public"
17:26:18.082 [info] "realtime:public:messages"
17:26:18.083 [info] "realtime:public:messages:channel_id=eq.1"
17:26:18.085 [error] GenServer #PID<0.2564.0> terminating
** (ArgumentError) argument error
    :erlang.bit_size(nil)
    (realtime) anonymous fn/3 in Realtime.Replication.notify_subscribers/1
    (elixir) lib/enum.ex:789: anonymous fn/3 in Enum.each/2
    (stdlib) maps.erl:232: :maps.fold_1/3
    (elixir) lib/enum.ex:1964: Enum.each/2
    (realtime) lib/realtime/replication.ex:237: anonymous fn/3 in Realtime.Replication.notify_subscribers/1
    (elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3
    (realtime) lib/realtime/replication.ex:217: Realtime.Replication.notify_subscribers/1
Last message: {:epgsql, #PID<0.2565.0>, {:x_log_data, 23616408, 23616408, <<67, 0, 0, 0, 0, 0, 1, 104, 91, 104, 0, 0, 0, 0, 1, 104, 91, 152, 0, 2, 66, 104, 141, 229, 100, 110>>}}

and

17:26:18.151 [info] CONNECTED TO RealtimeWeb.UserSocket in 178µs
  Transport: :websocket
  Serializer: Phoenix.Socket.V1.JSONSerializer
  Connect Info: %{}
  Parameters: %{"vsn" => "1.0.0"}
17:26:18.153 [error] GenServer #PID<0.2569.0> terminating
** (KeyError) key :record not found in: %Realtime.Adapters.Changes.DeletedRecord{columns: [%Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "id", type: "int8", type_modifier: 4294967295}, %Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "inserted_at", type: "timestamp", type_modifier: 4294967295}, %Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "updated_at", type: "timestamp", type_modifier: 4294967295}, %Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "data", type: "jsonb", type_modifier: 4294967295}, %Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "message", type: "text", type_modifier: 4294967295}, %Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "user_id", type: "int8", type_modifier: 4294967295}, %Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "channel_id", type: "int8", type_modifier: 4294967295}], commit_timestamp: ~U[2020-02-25 17:26:18Z], old_record: %{"channel_id" => "1", "data" => nil, "id" => "23", "inserted_at" => "2020-02-25 17:26:18.071593", "message" => "delete test", "updated_at" => "2020-02-25 17:26:18.071593", "user_id" => "1"}, schema: "public", table: "messages", type: "DELETE"}
    (realtime) lib/realtime/replication.ex:237: anonymous fn/3 in Realtime.Replication.notify_subscribers/1
    (elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3
    (realtime) lib/realtime/replication.ex:217: Realtime.Replication.notify_subscribers/1
    (realtime) lib/realtime/replication.ex:82: Realtime.Replication.process_message/2
    (realtime) lib/realtime/replication.ex:54: Realtime.Replication.handle_info/2
    (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: {:epgsql, #PID<0.2570.0>, {:x_log_data, 23616632, 23616632, <<67, 0, 0, 0, 0, 0, 1, 104, 92, 72, 0, 0, 0, 0, 1, 104, 92, 120, 0, 2, 66, 104, 141, 229, 243, 123>>}}

not sure if these are responsible but probably worth cleaning up anyway

@awalias awalias added the bug Something isn't working label Feb 25, 2020
kiwicopple added a commit that referenced this issue Feb 26, 2020
@kiwicopple
Copy link
Member

kiwicopple commented Feb 26, 2020

Dubugged these a bit
I think the culprit is this line.

As DELETE transactions don't have change.record to enumerate over (unless the user has set REPLICA IDENTITY FULL in postgres). It does have the "old_record" though (i think), so we might be able to enumerate over that instead

@kiwicopple
Copy link
Member

Looks good. The patch for the other issue just a matter of wrapping this block with an if change.record

image

The reason why (i think) is that this function is getting called when the replication starts, and there are no actual changes in the transaction.

Let's test your changes for now though. Do you need me to push to docker hub?

@awalias
Copy link
Member Author

awalias commented Mar 16, 2020

last remaining thing to fix is 04:33:14.166 [error] GenServer #PID<0.2513.0> terminating ** (KeyError) key :record not found in: %Realtime.Adapters.Changes.DeletedRecord{columns: [%Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "id", type: "int8", type_modifier: 4294967295}, %Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "inserted_at", type: "timestamp", type_modifier: 4294967295}, %Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "updated_at", type: "timestamp", type_modifier: 4294967295}, %Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "data", type: "jsonb", type_modifier: 4294967295}, %Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "message", type: "text", type_modifier: 4294967295}, %Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "user_id", type: "int8", type_modifier: 4294967295}, %Realtime.Decoder.Messages.Relation.Column{flags: [:key], name: "channel_id", type: "int8", type_modifier: 4294967295}], commit_timestamp: ~U[2020-03-16 04:33:14Z], old_record: %{"channel_id" => "1", "data" => nil, "id" => "50", "inserted_at" => "2020-03-16 04:33:14.144909", "message" => "delete test", "updated_at" => "2020-03-16 04:33:14.144909", "user_id" => "1"}, schema: "public", table: "messages", type: "DELETE"}

@awalias
Copy link
Member Author

awalias commented Mar 16, 2020

oh sorry just saw you already posted the fix above, will make the change now, I tested the previous fix and it works well

@awalias
Copy link
Member Author

awalias commented Mar 16, 2020

fixed in 0.7.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants