Can not connect to app running in internal network

kinsyudevPRO

5 months 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

Solved

0 Replies

kinsyudevPRO

5 months ago

a864dd2b-2b49-4eee-b5b2-627b3c084d43


kinsyudevPRO

5 months 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

1316886103407591400


kinsyudevPRO

5 months 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"}

kinsyudevPRO

5 months ago

When I test with my local docker container, it all seems to work correctly


kinsyudevPRO

5 months ago

Happy to provide more details if needed


5 months ago

is it listening on :: ?


kinsyudevPRO

4 months 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=localhost

Which is the resolved address for

--http --http.addr=lavish-liberation.railway.internal --ws --ws.addr=lavish-liberation.railway.internal

1317032116571078700


4 months ago

you don't want to listen on its IPv6 address


4 months ago

please have it listen on ::


kinsyudevPRO

4 months 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=localhost

kinsyudevPRO

4 months ago

It has the exact same issue


kinsyudevPRO

4 months 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 specified

kinsyudevPRO

4 months ago

1317033684527743000


4 months ago

hey now it's responding


4 months ago

now what host is it talking about


kinsyudevPRO

4 months ago

Thast's a good question


kinsyudevPRO

4 months ago

I initially had that issue, so I tried resolving to the internal network address


kinsyudevPRO

4 months 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.0

4 months ago

is there anything in the deploy logs that could help?


kinsyudevPRO

4 months ago

Nope, I see nothing in the logs when I get that error


kinsyudevPRO

4 months ago

If I look at the http logs, it shows a 403


kinsyudevPRO

4 months ago

1317034738078187500


4 months ago

so what even is sonic node?


kinsyudevPRO

4 months ago

It's an RPC node for a blockchain


kinsyudevPRO

4 months ago

by having it on railway it increases the speed of our operation by 5-6x (when it works <:kek:885396556520493056> )


4 months ago

I don't think our public proxy supports RPC


4 months ago

it's strictly http


kinsyudevPRO

4 months ago

But the RPC works over http, it's just a post request


4 months ago

does it? try the TCP proxy instead


kinsyudevPRO

4 months ago

on it


kinsyudevPRO

4 months 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 peer

4 months ago

the TCP proxy is pointing to the correct port right?


kinsyudevPRO

4 months ago

As far as I understand I send the RPC requests over HTTP POST or websocket with the payload as part of the body


kinsyudevPRO

4 months ago

yes

1317036280017584000


4 months ago

hmm well I'm not sure what to tell you, I'm not familiar with the software


kinsyudevPRO

4 months 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


kinsyudevPRO

4 months ago

Exact same setup as on Railway


4 months ago

what would you typically see when you open the domain in the browser?


kinsyudevPRO

4 months ago

nothing


kinsyudevPRO

4 months ago

The only way to see if it's working is by sending a post request with a simple method


kinsyudevPRO

4 months 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"}'

kinsyudevPRO

4 months 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"}

4 months ago

maybe it was never designed to work behind a proxy


kinsyudevPRO

4 months ago

Maybe


kinsyudevPRO

4 months ago

It's one source software, I'm happy to review the source if needed


kinsyudevPRO

4 months ago

What would be a pointer that it's not designed to work behind a proxy?


kinsyudevPRO

4 months ago

In case you're curious, this is the source https://github.com/Fantom-foundation/Sonic/tree/v2.0.1


4 months ago

find out what triggers "invalid host specified" to be returned, and don't return that error lol


kinsyudevPRO

4 months ago

<:kek:885396556520493056>


kinsyudevPRO

4 months ago

Alright, thank you for your time


4 months ago

i know we for sure pass through the Host value unmodified


kinsyudevPRO

4 months ago

Knowing that it's not a configuration error is a good start


kinsyudevPRO

4 months ago

I'll post my findings here


4 months ago

sounds good, wish I could have helped more!


kinsyudevPRO

4 months ago

@Brody Found a solution, turns out I had to enable a vhosts flag https://github.com/ethereum/go-ethereum/issues/16526#issuecomment-992480651


kinsyudevPRO

4 months ago

It's working now <:pog:925010410518749194>


kinsyudevPRO

4 months 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


kinsyudevPRO

4 months 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


kinsyudevPRO

4 months ago

but not idea 😄


4 months 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?


kinsyudevPRO

4 months ago

I don't really see it gracfully shutting down

1317212451002912800


4 months ago

the application would need to properly handle sigterm


4 months ago

you are using a volume right? and making sure data is actually being written to said volume


kinsyudevPRO

4 months 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


4 months ago

yeah we don't send ctrl + c haha, sigterm is a standardized way to tell an app to shut down


kinsyudevPRO

4 months ago

I know, I just expected both to send the same signal


kinsyudevPRO

4 months ago

Feel free to close the ticket btw, thanks for your help!


kinsyudevPRO

4 months ago

this is what it'd look like

1317222924029005800


4 months ago

yeah it's probably just listening in the wrong signal, sounds like an easy pr


4 months ago

yeah ctrl + c is sigint


kinsyudevPRO

4 months ago

    stopNodeSig := make(chan os.Signal, 1)
        signal.Notify(stopNodeSig, syscall.SIGINT, syscall.SIGTERM)
        defer signal.Stop(stopNodeSig)

        startFreeDiskSpaceMonitor(ctx, stopNodeSig, stack.InstanceDir())

        &lt;-stopNodeSig

kinsyudevPRO

4 months ago

looks like an easy PR indeed


kinsyudevPRO

4 months ago

I don't know much go but that looks like it should listen to SIGTERMs too


4 months ago

I know go and it looks like that will do what you need to


4 months ago

as long as 3 seconds is enough, but if it's not you can always up that time via railway


kinsyudevPRO

4 months ago

It should be more than enough, takes like under 100ms locally


kinsyudevPRO

4 months ago

Just in case, what's the parameter to up that in Railway?


4 months ago

perfect


4 months ago

RAILWAY_DEPLOYMENT_DRAINING_SECONDS


kinsyudevPRO

4 months ago

Thanks!


kinsyudevPRO

4 months ago

Tweaking this worked, skill issue on my end as per usual


4 months ago

happy to hear that


4 months ago

!s


Status changed to Solved brody 4 months ago