TGRHavoc / live_map

A FiveM addon for live maps
https://docs.tgrhavoc.co.uk/livemap-resource/
62 stars 38 forks source link

Bug: 'localhost' = 200, '127.0.0.1' = 404 #79

Closed matsn0w closed 2 years ago

matsn0w commented 2 years ago

Describe the bug I've found a strange issue when trying to access the blips.json file... When requesting localhost:30121/blips.json I get a 200 response, but when requesting 127.0.0.1:30121/blips.json, I receive a 404?

LOL, whut?

To Reproduce Steps to reproduce the behavior:

  1. Start a local server
  2. Start the live_map resource
  3. Request http://localhost:PORT/blips.json
  4. Request http://127.0.0.1:PORT/blips.json
  5. See error

Desktop (please complete the following information):

matsn0w commented 2 years ago

Strange thing is, txAdmin for example does work with both server addresses...?

TGRHavoc commented 2 years ago

That's wierd... It might be the way I'm initializing koa... Mind you, I don't specify a host so it should be listening on all interfaces https://stackoverflow.com/a/33957043/16288660.

Are you requesting these resources yourself or is it through the interface? If its through the interface, could you try accessing the interface through the same interface (so your URL matches the IP being requested). If that works then, it's probably the browser's CORS (https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) policy...

If it's not the browser and you're requesting these manually, let me know how you're requesting them (and the versions of Chromium) and I'll see if I can figure out a repro and fix.

matsn0w commented 2 years ago

Hey, it's weird indeed ;)

I've tried both requesting the file manually and through the interface, both give the same results! I'm not getting any CORS related warnings in the console.

Can you reproduce this?

TGRHavoc commented 2 years ago

Can you reproduce this?

Just had a look now with the latest resource and latest artifact... Cannot reproduce on Firefox (Version 96.0.4664.110 (Official Build) (64-bit)) nor Chrome (Version 96.0.4664.110 (Official Build) (64-bit)) e8c39ff71c98352512fb1655ab0214c43d6e1f78863f0921c1a48e0e1ad9 4897216a6eb6531b27d145211a56987b7ffa96f07795a1d8abee5eafcf7d

Windows version of curl: d7b1ad5847f3a7a8c86d15e80f266ffb2c326d51614f183ad030a381440c

And Edge (Version 96.0.1054.62 (Official build) (64-bit)): 4daf074e6be35f0f043c8864c182bf2c8bd8918f49267fdbd823067412d1

I am still on Windows 10 though and don't have a Windows 11 machine to test on (maybe the OS is fucky with the different addresses even though they're the same thing).

Ps. Sorry for the late response, only spare time I've manage to find 😛

matsn0w commented 2 years ago

Hey, thanks for your testing. Appreciate your time :)

I'm starting to think that this is indeed a Windows 11 issue... My curl results:

image

I've also updated my test server to the latest recommended artifact, but with no luck.

matsn0w commented 2 years ago

Thing is, it's also not working on our server. Both using the direct IP and a 'written' hostname give the same 404 result. Could it be my config?

# live map
set socket_port 30140
set livemap_debug "warn" # "[all]" 'trace', 'debug', 'info', 'warn', 'error', 'fatal', 'off'
set blip_file "server/blips.json"
set livemap_access_control "*"
set livemap_use_nucleus false # Allow livemap to set up a secure reverseProxy using the Nucleus project

add_ace group.admin command.blips allow
matsn0w commented 2 years ago

BTW, server is on Linux, so if this is the same problem it shouldn't be related to Windows I guess.

TGRHavoc commented 2 years ago

Tbh. That looks like it could be a FiveM error message. Do you get a result if you get /players.json or /info.json?

matsn0w commented 2 years ago

Interesting... This is the other way around 😂

image

TGRHavoc commented 2 years ago

Yeah... So for some reason it looks like FiveM is binding to the socket port on 127.0.0.1 and LiveMap is getting localhost.... Even though localhost should be pointing to 127.0.0.1 (or something I think I know is wrong)... I can maybe get a potential fix up on a new branch for you to try (it'll just be giving koa the 0.0.0.0 interface to listen on).

You don't have FiveM listening on the same port, do you? :joy:

matsn0w commented 2 years ago

Yeah... So for some reason it looks like FiveM is binding to the socket port on 127.0.0.1 and LiveMap is getting localhost.... Even though localhost should be pointing to 127.0.0.1 (or something I think I know is wrong)... I can maybe get a potential fix up on a new branch for you to try (it'll just be giving koa the 0.0.0.0 interface to listen on).

Ah, yeah if you'd like to do that, please!

You don't have FiveM listening on the same port, do you? 😂

Our server is a little different in many ways 😉

TGRHavoc commented 2 years ago

Okay, could you try both branches and see if any fix your issue.

https://github.com/TGRHavoc/live_map/tree/matsn0w/0.0.0.0 https://github.com/TGRHavoc/live_map/tree/matsn0w/127.0.0.1

If they do, I'll merge into master 😄

matsn0w commented 2 years ago

Woohoo 🙌

The version with 127.0.0.1 is working! The other one gives me an error on startup, saying Error: listen EADDRINUSE: address already in use 0.0.0.0:30140

image ^^ first two are on 0.0.0.0, second two on 127.0.0.1

TGRHavoc commented 2 years ago

Perfect. I'll merge as soon as I can.

Curious as to why you're getting conflicting addresses... FiveM shouldn't be listening on that port unless told to...

matsn0w commented 2 years ago

Curious as to why you're getting conflicting addresses... FiveM shouldn't be listening on that port unless told to...

I absolutely have no clue. Last thing I can think of is Docker running on my machine. Server is also Docker-based.

matsn0w commented 2 years ago

@TGRHavoc small follow-up; I've updated the resource on our server, but I'm getting this error:

[    c-scripting-core] Creating script environments for live_map
[script:live_map] LiveMap will not use nucleus
[ citizen-server-impl] Started resource live_map
[script:live_map] Error calling system tick function in resource live_map: Error: listen EADDRINUSE: address already in use 127.0.0.1:30140
[script:live_map] stack:
[script:live_map] Error: listen EADDRINUSE: address already in use 127.0.0.1:30140
[script:live_map]     at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
[script:live_map]     at __node_internal_uvExceptionWithHostPort (node:internal/errors:563:12)
[script:live_map]     at Server.setupListenHandle [as _listen2] (node:net:1319:16)
[script:live_map]     at listenInCluster (node:net:1367:12)
[script:live_map]     at doListen (node:net:1505:7)
[script:live_map]     at processTicksAndRejections (node:internal/process/task_queues:84:21)
[script:live_map]     at process.runNextTicks [as _tickCallback] (node:internal/process/task_queues:65:3)
[script:live_map]     at onTick (citizen:/scripting/v8/timer.js:222:28)
[script:live_map]     at citizen:/scripting/v8/timer.js:265:13
[script:live_map]     at Number.__cfx_wrap_5 (citizen:/scripting/v8/main.js:23:12)
[script:live_map]     at citizen:/scripting/v8/main.js:29:16
[script:live_map]     at citizen:/scripting/v8/timer.js:264:16

Any idea how this is possible?

TGRHavoc commented 2 years ago

:thinking: I feel that somehow either FiveM is taking the socket port for itself or, the resource isn't exiting cleanly and removing the handler on that port... Making it in use.

matsn0w commented 2 years ago

Tested on the server without any other resources enabled, still same issue. I'm contacting my hosting company to see if they can have a look into this.

I don't have this issue locally by the way.

matsn0w commented 2 years ago

Obviously I must use a different port for the socket than the server. The host is setting up a different one for us, let's see if that works!

Kraleemil commented 2 years ago

Obviously I must use a different port for the socket than the server. The host is setting up a different one for us, let's see if that works!

Did it work with a defirnt one i have the same problem with 30121

matsn0w commented 2 years ago

Obviously I must use a different port for the socket than the server. The host is setting up a different one for us, let's see if that works!

Did it work with a defirnt one i have the same problem with 30121

Problem seems to be related to the host.