Closed cutecutecat closed 1 year ago
Possibly related to #665
I am having the same issue. I'm running npx supabase start
and then npx supabase db diff
inside the Github Codespace (4-core, 16GB RAM, 32GB)
Console output:
@unaimillan ➜ /workspaces/ProStart (dev) $ npx supabase db diff
Connecting to local database...
Creating shadow database...
failed to connect to `host=localhost user=postgres database=postgres`: failed to receive message (read tcp [::1]:60690->[::1]:54320: read: connection reset by peer)
Try rerunning the command with --debug to troubleshoot the error.
The following attempts to run the diff
result in following:
@unaimillan ➜ /workspaces/ProStart (dev) $ npx supabase db diff --debug
Supabase CLI 1.83.7
Connecting to local database...
2023/08/08 15:20:50 Connect Start: tcp 127.0.0.1:54322
2023/08/08 15:20:50 Connect Done: tcp 127.0.0.1:54322
``` 2023/08/08 15:20:50 PG Send: {"Type":"StartupMessage","ProtocolVersion":196608,"Parameters":{"database":"postgres","user":"postgres"}} 2023/08/08 15:20:50 PG Recv: {"Type":"AuthenticationSASL","AuthMechanisms":["SCRAM-SHA-256"]} 2023/08/08 15:20:50 PG Send: {"Type":"SASLInitialResponse","AuthMechanism":"SCRAM-SHA-256","Data":"n,,n=,r=cqLkD34PlEqLY9G5Gz/jwEZa"} 2023/08/08 15:20:50 PG Recv: {"Type":"AuthenticationSASLContinue","Data":"r=cqLkD34PlEqLY9G5Gz/jwEZaR2eEPYnp3ZPe5uNwwBGHnFHf,s=xcSazfYEPnP9sIlODnoh9w==,i=4096"} 2023/08/08 15:20:50 PG Send: {"Type":"SASLResponse","Data":"c=biws,r=cqLkD34PlEqLY9G5Gz/jwEZaR2eEPYnp3ZPe5uNwwBGHnFHf,p=wh5Gh0VNcAGJCkqxC49YKFFeRYyI6QRwDZ/tMeVQe6s="} 2023/08/08 15:20:50 PG Recv: {"Type":"AuthenticationSASLFinal","Data":"v=UP4XzPaA8bds5A5FF35KAfE/Qc8YpYq3/o5GjWZVavY="} 2023/08/08 15:20:50 PG Recv: {"Type":"AuthenticationOK"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"application_name","Value":""} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"client_encoding","Value":"UTF8"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"DateStyle","Value":"ISO, MDY"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"default_transaction_read_only","Value":"off"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"in_hot_standby","Value":"off"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"integer_datetimes","Value":"on"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"IntervalStyle","Value":"postgres"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"is_superuser","Value":"off"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"server_encoding","Value":"UTF8"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"server_version","Value":"15.1 (Ubuntu 15.1-1.pgdg20.04+1)"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"session_authorization","Value":"postgres"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"standard_conforming_strings","Value":"on"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterStatus","Name":"TimeZone","Value":"UTC"} 2023/08/08 15:20:50 PG Recv: {"Type":"BackendKeyData","ProcessID":11316,"SecretKey":3299768426} 2023/08/08 15:20:50 PG Recv: {"Type":"ReadyForQuery","TxStatus":"I"} 2023/08/08 15:20:50 PG Send: {"Type":"Parse","Name":"lrupsc_1_0","Query":"SELECT schema_name FROM information_schema.schemata WHERE NOT schema_name LIKE ANY($1) ORDER BY schema_name","ParameterOIDs":null} 2023/08/08 15:20:50 PG Send: {"Type":"Describe","ObjectType":"S","Name":"lrupsc_1_0"} 2023/08/08 15:20:50 PG Send: {"Type":"Sync"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParseComplete"} 2023/08/08 15:20:50 PG Recv: {"Type":"ParameterDescription","ParameterOIDs":[1009]} 2023/08/08 15:20:50 PG Recv: {"Type":"RowDescription","Fields":[{"Name":"schema_name","TableOID":13330,"TableAttributeNumber":2,"DataTypeOID":19,"DataTypeSize":64,"TypeModifier":-1,"Format":0}]} 2023/08/08 15:20:50 PG Recv: {"Type":"ReadyForQuery","TxStatus":"I"} 2023/08/08 15:20:50 PG Send: {"Type":"Bind","DestinationPortal":"","PreparedStatement":"lrupsc_1_0","ParameterFormatCodes":[1],"Parameters":[{"binary":"00000001000000000000001900000018000000010000000461757468000000097067626f756e636572000000087265616c74696d650000000a5c5f7265616c74696d650000000773746f726167650000000b5c5f616e616c79746963730000001373757061626173655c5f66756e6374696f6e730000001473757061626173655c5f6d6967726174696f6e7300000013696e666f726d6174696f6e5c5f736368656d610000000570675c5f250000000463726f6e000000076772617068716c0000000f6772617068716c5c5f7075626c6963000000036e6574000000087067736f6469756d0000000f7067736f6469756d5c5f6d61736b73000000057067746c650000000672657061636b0000000574696765720000000b74696765725c5f646174610000000e74696d657363616c6564625c5f25000000105c5f74696d657363616c6564625c5f2500000008746f706f6c6f6779000000057661756c74"}],"ResultFormatCodes":[1]} 2023/08/08 15:20:50 PG Send: {"Type":"Describe","ObjectType":"P","Name":""} 2023/08/08 15:20:50 PG Send: {"Type":"Execute","Portal":"","MaxRows":0} 2023/08/08 15:20:50 PG Send: {"Type":"Sync"} 2023/08/08 15:20:50 PG Recv: {"Type":"BindComplete"} 2023/08/08 15:20:50 PG Recv: {"Type":"RowDescription","Fields":[{"Name":"schema_name","TableOID":13330,"TableAttributeNumber":2,"DataTypeOID":19,"DataTypeSize":64,"TypeModifier":-1,"Format":1}]} 2023/08/08 15:20:50 PG Recv: {"Type":"DataRow","Values":[{"text":"extensions"}]} 2023/08/08 15:20:50 PG Recv: {"Type":"DataRow","Values":[{"text":"public"}]} 2023/08/08 15:20:50 PG Recv: {"Type":"CommandComplete","CommandTag":"SELECT 2"} 2023/08/08 15:20:50 PG Recv: {"Type":"ReadyForQuery","TxStatus":"I"} Creating shadow database... 2023/08/08 15:20:50 Sent Header: Host [api.moby.localhost] 2023/08/08 15:20:50 Sent Header: User-Agent [Docker-Client/unknown-version (linux)] 2023/08/08 15:20:50 Sent Header: X-Meta-Source-Client [github/codespaces] 2023/08/08 15:20:50 Send Done 2023/08/08 15:20:50 PG Send: {"Type":"Terminate"} 2023/08/08 15:20:50 Recv First Byte 2023/08/08 15:20:50 Sent Header: Host [api.moby.localhost] 2023/08/08 15:20:50 Sent Header: User-Agent [Docker-Client/unknown-version (linux)] 2023/08/08 15:20:50 Sent Header: Content-Length [306] 2023/08/08 15:20:50 Sent Header: Content-Type [application/json] 2023/08/08 15:20:50 Sent Header: X-Meta-Source-Client [github/codespaces] 2023/08/08 15:20:50 Send Done 2023/08/08 15:20:50 Recv First Byte 2023/08/08 15:20:50 Sent Header: Host [api.moby.localhost] 2023/08/08 15:20:50 Sent Header: User-Agent [Docker-Client/unknown-version (linux)] 2023/08/08 15:20:50 Sent Header: Content-Length [11322] 2023/08/08 15:20:50 Sent Header: Content-Type [application/json] 2023/08/08 15:20:50 Sent Header: X-Meta-Source-Client [github/codespaces] 2023/08/08 15:20:50 Send Done 2023/08/08 15:20:51 Recv First Byte ```
2023/08/08 15:20:51 Sent Header: Host [api.moby.localhost]
2023/08/08 15:20:51 Sent Header: User-Agent [Docker-Client/unknown-version (linux)]
2023/08/08 15:20:51 Sent Header: Content-Length [0]
2023/08/08 15:20:51 Sent Header: Content-Type [text/plain]
2023/08/08 15:20:51 Sent Header: X-Meta-Source-Client [github/codespaces]
2023/08/08 15:20:51 Send Done
2023/08/08 15:20:51 Recv First Byte
Error response from daemon: driver failed programming external connectivity on endpoint pensive_lewin (f98839c84ac52a2f15c6481cc5a6bb29f8d64d73cfdb0b4ef0bd2efb6674c114): Bind for 0.0.0.0:54320 failed: port is already allocated
@cutecutecat Have you managed to solve the issue?
Also small question or proposal (probably to @sweatybridge if related):
Is it possible and makes any sense to name the Shadow Database container in the same fashion as all other containers like supabase_shadowdb_<folder>
?
As a temporary workaround for my gh codespace, I have done the following:
migra
tool into the VM with pip install psycopg2-binary
and pip install migra
docker run --rm -it --name supa_shadow -e POSTGRES_PASSWORD=postgres -p 54320:5432 supabase/postgres:15.1.0.103
(in the separate terminal)cat supabase/migrations/* | docker exec -i supa_shadow psql -U postgres
migra
tool to get the migration plan with migra --schema public postgresql://postgres:postgres@localhost:54320/postgres postgresql://postgres:postgres@localhost:54322/postgres
@unaimillan Awesome, it works.
I can reproduce this error in GitHub Codespaces. I will fix it in the next release by waiting for shadow database health check.
Is it possible and makes any sense to name the Shadow Database container in the same fashion as all other containers like supabaseshadowdb
?
It is possible to use a predictable name but it means users will lose the ability to run multiple db diff
commands at the same time to check against different remote in CI. I would avoid breaking this use case if possible.
Describe the bug This bug is hard to reproduce.
Running
supabase diff
will start apostgres
instance as shadow database, andDial
to it then.However,
postgres
image will shutdown first at run, and then start, as https://stackoverflow.com/a/37437238 says.At some machines,
supabase cli's
Dial will be sent before databse service available, and lead to a connection reset.To Reproduce This bug could only be reproduced on a small number of devices!
supabase diff ...
connection reset
Expected behavior Command runs gracefully, and output diff schema.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Log of supabase cli:
Log of shadow postgres container:
We can see service is available at
07:43:44.942
and crash happens at15:43:33
. P.S. The difference of hour display is caused by UTC+8, and could be neglect.How to fix Maybe some
retry-on-failed
orservice probe
technique will help.