#community-help

Server IP Address and Port Issues with Typesense

TLDR Alex encountered problems with Typesense server configuration when setting IP and port using --api-address and --api-port, facing additional problems with CORS and version inequities. Kishore Nallan addressed each point, ultimately finding a bug with the command line parser affecting subsequent commands. The advised workaround was to use --enable-cors=true.

Powered by Struct AI

1

Apr 08, 2022 (21 months ago)
Alex
Photo of md5-dc362c4060d01d7ad6c9211157de3d69
Alex
09:39 AM
IP weirdness with TS server:
when I start typesense specifying an IP / PORT like so:
--api-address 159.203.31.163 \
--api-port=80

but then I get this:
typesense TCP 10.20.0.5:8107 (LISTEN)
typesense TCP 159.203.31.163:80 (LISTEN)

and in the TS log I can see the 10.x IP being used, while there is nothing listening on that IP on port 80:
CURL failed. URL: http://10.20.0.5:80/health, Code: 7, strerror: Couldn't connect to server
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:41 AM
There are two address configs. One for api http service which is configured via --api-address and the other is for the raft port that listens on 8107 -- this raft listener uses an internal interface only by default.
Alex
Photo of md5-dc362c4060d01d7ad6c9211157de3d69
Alex
09:42 AM
ok, but why does TS try to connect to port 80 for a health check on that internal IP?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:42 AM
It shouldn't.
09:42
Kishore Nallan
09:42 AM
Check the logs to see if there are any errors with api port binding.
09:43
Kishore Nallan
09:43 AM
If you have SSL configured you need to use https while curling.
Alex
Photo of md5-dc362c4060d01d7ad6c9211157de3d69
Alex
09:44 AM
This is not something I'm doing, I'm assuming TS does some selfcheck on the wrong IP/PORT: CURL failed. URL: http://10.20.0.5:80/health, Code: 7, strerror: Couldn't connect to server
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:45 AM
Oh you see that in the logs?
Alex
Photo of md5-dc362c4060d01d7ad6c9211157de3d69
Alex
09:45 AM
yup it's in the nohup error log
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:46 AM
Are you using clustering?
Alex
Photo of md5-dc362c4060d01d7ad6c9211157de3d69
Alex
09:46 AM
not in this case no.
09:47
Alex
09:47 AM
nohup ./typesense-server --data-dir=/home/alex/tsdata --api-key=$TYPESENSE_API_KEY --enable-cors \
--api-address 159.203.31.163 \
--api-port=80 \
--log-dir=/home/alex/tsdata/log
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:47 AM
Can you add a equals after --api-address flag?
Alex
Photo of md5-dc362c4060d01d7ad6c9211157de3d69
Alex
09:47 AM
sure
11:29
Alex
11:29 AM
So when I started version 23.rc47 it seemed to ignore the api-address line altogether and bind to * . I didn't see any of the healthcheck errors in the log, but also binding to * might explain that.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:35 AM
Oh okay, we did make one recent change related to this part. I will take a look.
Alex
Photo of md5-dc362c4060d01d7ad6c9211157de3d69
Alex
11:37 AM
my JS client had a issues connecting to rc47 too
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:38 AM
We've other customers using rc47 though. Maybe they don't use custom API address.
11:38
Kishore Nallan
11:38 AM
Do you have multiple public IPs? Otherwise binding to * is generally fine since you do intend to expose it to internet.
Alex
Photo of md5-dc362c4060d01d7ad6c9211157de3d69
Alex
11:58 AM
So when I remove the --api-address line then 23.RC47 also ignores --api-port=80 and binds to: *:8108
12:07
Alex
12:07 PM
ApiCall.ts:203 Request #1649419591544: Request to Node 0 failed due to "undefined Network Error"
performRequest @ ApiCall.ts:203
ApiCall.ts:205 Request #1649419591544: Sleeping for 0.1s and then retrying request...
performRequest @ ApiCall.ts:205
localhost/multi_search?x-typesense-api-key=xyz:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
ApiCall.ts:203 Request #1649419591544: Request to Node 0 failed due to "undefined Network Error"
performRequest @ ApiCall.ts:203
ApiCall.ts:205 Request #1649419591544: Sleeping for 0.1s and then retrying request...
performRequest @ ApiCall.ts:205
localhost/multi_search?x-typesense-api-key=xyz:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
12:08
Alex
12:08 PM
but curl connects just fine
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:25 PM
Ok will look at this and get back to you.
Apr 09, 2022 (21 months ago)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:29 AM
We're indeed using the internal IP for an internal health call which happens after a snapshot. But for single node setup, this is not critical and should not affect the server ops.

If you just remove the api-address config, Typesense will listen on all interfaces or can also explicitly use:

--api-address=0.0.0.0
02:08
Kishore Nallan
02:08 AM
This is how Typesense has always been, so maybe you've never set this config directly before so didn't notice this problem? Despite that error, single node operations won't be anwyay affected.
Alex
Photo of md5-dc362c4060d01d7ad6c9211157de3d69
Alex
05:42 AM
Well they are affected: My JS code which comes from your Ecommerce example is no longer able to connect to the single 23.RC47 node. And If I do remove the --api-address line from startup, --api-port=80 is ignored. so 23.RC47 is unable to have a port set unless an --api-address line is in the config
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
05:46 AM
I'm just trying this locally and removing api address has no impact on port. So very strange... Let me try again on a Linux box. Was trying on local mac.
Alex
Photo of md5-dc362c4060d01d7ad6c9211157de3d69
Alex
06:52 AM
I'm thinking it also might be ignoring the --enable-cors switch as the error I get with RC47 is: Access to XMLHttpRequest at 'http://159.203.31.163/multi_search?x-typesense-api-key=xyz' from origin 'http://alex.pc-america.com:3010' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
06:53
Alex
06:53 AM
Same code works fine with 22.2
06:53
Alex
06:53 AM
nohup ./typesense-server --data-dir=/home/alex/tsdata --api-key=$TYPESENSE_API_KEY --enable-cors \
--api-address=0.0.0.0 \
--api-port=80 \
--log-dir=/home/alex/tsdata/log
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:16 AM
Oh right it might be a cors issue.
Alex
Photo of md5-dc362c4060d01d7ad6c9211157de3d69
Alex
07:18 AM
I could try with a different 23.RC maybe?
11:04
Alex
11:04 AM
Alternatively is there a way to check if cors is enabled? like some sort of display current config command that can be issued to TS?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:10 PM
The response header should have access-control-allow-origin as *

I've been AFK so haven't been able to investigate yet, sorry. Will keep you posted.
Alex
Photo of md5-dc362c4060d01d7ad6c9211157de3d69
Alex
02:46 PM
no rush 😉
Apr 10, 2022 (21 months ago)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:08 AM
Turned out to be an annoying bug with the command line parser. People were trying to enable cors by send a true value, like --enable-cors=true which the argument parsing library that Typesense uses does not support. In trying to fix that, ended up introducing a bug where any flag sent after the enable-cors option becomes interpreted as a value of the enable-cors flag, so when your command is:

--enable-cors --api-address=0.0.0.0

it set the enable-cors value as "--api-address=0.0.0.0" :face_palm:

Until I fix this parsing issue in a future build, please use --enable-cors=true so it's explicit.

1

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3015 threads (79% resolved)

Join Our Community

Similar Threads