2 years ago
Hi,
I'm running a docker container that exposed an HTTP server. I am trying to connect to it both through internal networking and external through creating a proxy and I can't get any of them working.
I can run this same container locally and communicate with it just fine. Not sure what I'm doing wrong here.
This is the repo I'm running https://github.com/0xFluffyBeard/sonic-node-docker
83 Replies
2 years ago
a864dd2b-2b49-4eee-b5b2-627b3c084d43
2 years ago
I get this error when trying to access it externally
curl -X POST https://sonic-node-production.up.railway.app -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":0,"method":"eth_blockNumber"}'
-------
{"status":"error","code":502,"message":"Application failed to respond","request_id":"lkW-NHaVTzaLfux9H3rXOA_3500563535"}%And a 403 when trying to access it from within the local network

2 years ago
curl -X POST http://localhost:18545 -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":0,"method":"eth_blockNumber"}'
-------
{"jsonrpc":"2.0","id":0,"result":"0x55151"}2 years ago
When I test with my local docker container, it all seems to work correctly
2 years ago
Happy to provide more details if needed
2 years ago
is it listening on :: ?
2 years ago
Right now it's listening on
INFO [12-12|20:28:09.013] HTTP server started endpoint=[fd12:e16:9f4f:0:4000:a:9ded:4c28]:18545 auth=false prefix= cors= vhosts=localhostWhich is the resolved address for
--http --http.addr=lavish-liberation.railway.internal --ws --ws.addr=lavish-liberation.railway.internal
2 years ago
you don't want to listen on its IPv6 address
2 years ago
please have it listen on ::
2 years ago
I've just created a new one listening on ::
INFO [12-13|07:38:38.806] HTTP server started endpoint=[::]:18545 auth=false prefix= cors= vhosts=localhost2 years ago
It has the exact same issue
2 years ago
curl -X POST https://sonic-node-docker-production.up.railway.app -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":0,"method":"eth_blockNumber"}'
-------
invalid host specified2 years ago

2 years ago
hey now it's responding
2 years ago
now what host is it talking about
2 years ago
Thast's a good question
2 years ago
I initially had that issue, so I tried resolving to the internal network address
2 years ago
Not sure how relevant it is, but I'm setting the following env variables
RUN_CMD_ARGS=--http --http.addr=0.0.0.0 --ws --ws.addr=0.0.0.02 years ago
is there anything in the deploy logs that could help?
2 years ago
Nope, I see nothing in the logs when I get that error
2 years ago
If I look at the http logs, it shows a 403
2 years ago

2 years ago
so what even is sonic node?
2 years ago
It's an RPC node for a blockchain
2 years ago
by having it on railway it increases the speed of our operation by 5-6x (when it works <:kek:885396556520493056> )
2 years ago
I don't think our public proxy supports RPC
2 years ago
it's strictly http
2 years ago
But the RPC works over http, it's just a post request
2 years ago
does it? try the TCP proxy instead
2 years ago
on it
2 years ago
Tried both http and https, got error on both
curl -v -X POST https://junction.proxy.rlwy.net:29067 -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":0,"method":"eth_blockNumber"}'
Note: Unnecessary use of -X or --request, POST is already inferred.
* Host junction.proxy.rlwy.net:29067 was resolved.
* IPv6: (none)
* IPv4: 35.214.222.137
* Trying 35.214.222.137:29067...
* Connected to junction.proxy.rlwy.net (35.214.222.137) port 29067
* ALPN: curl offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
* CAfile: /etc/ssl/cert.pem
* CApath: none
* Recv failure: Connection reset by peer
* LibreSSL/3.3.6: error:02FFF036:system library:func(4095):Connection reset by peer
* Closing connection
curl: (35) Recv failure: Connection reset by peer
❯ curl -v -X POST http://junction.proxy.rlwy.net:29067 -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":0,"method":"eth_blockNumber"}'
Note: Unnecessary use of -X or --request, POST is already inferred.
* Host junction.proxy.rlwy.net:29067 was resolved.
* IPv6: (none)
* IPv4: 35.214.222.137
* Trying 35.214.222.137:29067...
* Connected to junction.proxy.rlwy.net (35.214.222.137) port 29067
> POST / HTTP/1.1
> Host: junction.proxy.rlwy.net:29067
> User-Agent: curl/8.7.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 51
>
* upload completely sent off: 51 bytes
* Recv failure: Connection reset by peer
* Closing connection
curl: (56) Recv failure: Connection reset by peer2 years ago
the TCP proxy is pointing to the correct port right?
2 years ago
As far as I understand I send the RPC requests over HTTP POST or websocket with the payload as part of the body
2 years ago
yes

2 years ago
hmm well I'm not sure what to tell you, I'm not familiar with the software
2 years ago
Not sure what else to try myself, I have it running locally without issues, I set it up on a VPS last night to test and it also runs just fine
2 years ago
Exact same setup as on Railway
2 years ago
what would you typically see when you open the domain in the browser?
2 years ago
nothing
2 years ago
The only way to see if it's working is by sending a post request with a simple method
2 years ago
This would be the simplest one
curl -X POST http://localhost:18545 -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":0,"method":"eth_blockNumber"}'2 years ago
This is what the result looks like
❯ curl -X POST http://localhost:18545 -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":0,"method":"eth_blockNumber"}'
{"jsonrpc":"2.0","id":0,"result":"0x583f7"}2 years ago
maybe it was never designed to work behind a proxy
2 years ago
Maybe
2 years ago
It's one source software, I'm happy to review the source if needed
2 years ago
What would be a pointer that it's not designed to work behind a proxy?
2 years ago
In case you're curious, this is the source https://github.com/Fantom-foundation/Sonic/tree/v2.0.1
2 years ago
find out what triggers "invalid host specified" to be returned, and don't return that error lol
2 years ago
<:kek:885396556520493056>
2 years ago
Alright, thank you for your time
2 years ago
i know we for sure pass through the Host value unmodified
2 years ago
Knowing that it's not a configuration error is a good start
2 years ago
I'll post my findings here
2 years ago
sounds good, wish I could have helped more!
2 years ago
@Brody Found a solution, turns out I had to enable a vhosts flag https://github.com/ethereum/go-ethereum/issues/16526#issuecomment-992480651
2 years ago
It's working now <:pog:925010410518749194>
2 years ago
Another question on the topic, is there any way to gracefully shutdown a deployment? When making changes and re-deploying, it seems to just kill the container which corrupts the databse and makes it so we have to wipe the volume and re-index the entire blockchain, which is ~2h
2 years ago
It's not the end of the world since we can just keep two deployments open at all times and use one of them as a failover
2 years ago
but not idea 😄
2 years ago
old deployments are always gracefully shut down.
when the system goes to remove a deployment it is sent sigterm and then waits 3 seconds before force killing, is that 3 seconds not enough?
2 years ago
I don't really see it gracfully shutting down

2 years ago
the application would need to properly handle sigterm
2 years ago
you are using a volume right? and making sure data is actually being written to said volume
2 years ago
Looks like it's an implementation issue, when shutting down through a ctrl + c on the console it does gracefully shutdown, but I can't seem to be able to do the same on Docker
2 years ago
yeah we don't send ctrl + c haha, sigterm is a standardized way to tell an app to shut down
2 years ago
I know, I just expected both to send the same signal
2 years ago
Feel free to close the ticket btw, thanks for your help!
2 years ago
this is what it'd look like

2 years ago
yeah it's probably just listening in the wrong signal, sounds like an easy pr
2 years ago
yeah ctrl + c is sigint
2 years ago
stopNodeSig := make(chan os.Signal, 1)
signal.Notify(stopNodeSig, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(stopNodeSig)
startFreeDiskSpaceMonitor(ctx, stopNodeSig, stack.InstanceDir())
<-stopNodeSig2 years ago
looks like an easy PR indeed
2 years ago
I don't know much go but that looks like it should listen to SIGTERMs too
2 years ago
I know go and it looks like that will do what you need to
2 years ago
as long as 3 seconds is enough, but if it's not you can always up that time via railway
2 years ago
It should be more than enough, takes like under 100ms locally
2 years ago
Just in case, what's the parameter to up that in Railway?
2 years ago
perfect
2 years ago
RAILWAY_DEPLOYMENT_DRAINING_SECONDS
2 years ago
Thanks!
2 years ago
Tweaking this worked, skill issue on my end as per usual
2 years ago
happy to hear that
2 years ago
!s
Status changed to Solved brody • over 1 year ago