jordanpotter / docker-mods

MIT License
4 stars 3 forks source link

failed to add port mapping: recvfrom: connection refused #2

Open alexg-k opened 1 year ago

alexg-k commented 1 year ago

I repeatedly get the error message failed to add port mapping: read udp 127.0.0.1:54156->127.0.0.11:5351: recvfrom: connection refused when using your docker-mod. Maybe by looking at my compose file and the error log, you can advice me where to look next. Thanks!

compose.yaml

services:
  wireguard:
    image: linuxserver/wireguard:latest
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    sysctls:
      - net.ipv6.conf.all.disable_ipv6=0
        #- net.ipv4.conf.all.src_valid_mark=1
    environment:
      - PUID=1000
      - PGID=1000
    ports:
      - "9091:9091/tcp"
      - "9696:9696/tcp"
    volumes:
      - ./wg0.conf:/config/wg0.conf
      - /lib/modules:/lib/modules
    restart: unless-stopped

  transmission:
    image:  linuxserver/transmission:latest
    network_mode: "service:wireguard"
    depends_on:
      - wireguard
    environment:
      - DOCKER_MODS=jordanpotter/docker-mods:transmission-nat-pmp
      - PUID=1000
      - PGID=1000
    env_file:
      - ./transmission.env
    volumes:
      - config:/config
      - downloads:/downloads
      - watch:/watch
    restart: unless-stopped

And here are the error messages:

[...]
compose-transmission-wireguard-transmission-1  | [custom-init] No custom files found, skipping...
compose-transmission-wireguard-transmission-1  | 2023/08/12 10:54:41 failed to add port mapping: read udp 127.0.0.1:51591->127.0.0.11:5351: recvfrom: connection refused
compose-transmission-wireguard-transmission-1  | setsockopt IP_MULTICAST_IF: Address not available
compose-transmission-wireguard-transmission-1  | bind: Address not available
compose-transmission-wireguard-prowlarr-1      | [Info] Microsoft.Hosting.Lifetime: Application started. Press Ctrl+C to shut down. 
compose-transmission-wireguard-prowlarr-1      | [Info] Microsoft.Hosting.Lifetime: Hosting environment: Production 
compose-transmission-wireguard-prowlarr-1      | [Info] Microsoft.Hosting.Lifetime: Content root path: /app/prowlarr/bin 
compose-transmission-wireguard-prowlarr-1      | [ls.io-init] done.
compose-transmission-wireguard-transmission-1  | 2023/08/12 10:54:42 failed to add port mapping: read udp 127.0.0.1:53213->127.0.0.11:5351: recvfrom: connection refused
compose-transmission-wireguard-transmission-1  | Connection to localhost
compose-transmission-wireguard-transmission-1  |  (127.0.0.1) 9091 port [tcp/*] succeeded!
compose-transmission-wireguard-transmission-1  | [ls.io-init] done.
compose-transmission-wireguard-transmission-1  | [2023-08-12 10:54:42.894] ERR net.cc:318 Couldn't bind port 61932 on 10.2.0.2: Address not available (99) (net.cc:318)
compose-transmission-wireguard-transmission-1  | 2023/08/12 10:54:43 failed to add port mapping: read udp 127.0.0.1:49067->127.0.0.11:5351: recvfrom: connection refused
compose-transmission-wireguard-transmission-1  | 2023/08/12 10:54:44 failed to add port mapping: read udp 127.0.0.1:39823->127.0.0.11:5351: recvfrom: connection refused
compose-transmission-wireguard-transmission-1  | 2023/08/12 10:54:45 failed to add port mapping: read udp 127.0.0.1:35210->127.0.0.11:5351: recvfrom: connection refused
compose-transmission-wireguard-transmission-1  | 2023/08/12 10:54:46 failed to add port mapping: read udp 127.0.0.1:32914->127.0.0.11:5351: recvfrom: connection refused
compose-transmission-wireguard-transmission-1  | 2023/08/12 10:54:47 failed to add port mapping: read udp 127.0.0.1:45919->127.0.0.11:5351: recvfrom: connection refused
compose-transmission-wireguard-transmission-1  | 2023/08/12 10:54:48 failed to add port mapping: read udp 127.0.0.1:48531->127.0.0.11:5351: recvfrom: connection refused
compose-transmission-wireguard-transmission-1  | 2023/08/12 10:54:49 failed to add port mapping: read udp 127.0.0.1:54156->127.0.0.11:5351: recvfrom: connection refused
[...]
Flowwwww commented 11 months ago

Same issue here. It works at first but after some time it fails with the same logs.

Doing a docker compose down and a docker compose up again make it work again but this is not ideal.

jordanpotter commented 11 months ago

In my own use, I've noticed something similar. Things will work fine, then requests to port 5351 of the VPN provider will fail, and later requests will succeed again.

I believe this is because the VPN provider's NAT-PMP service is unstable. After all, no VPN provider is guaranteeing 100% uptime for NAT-PMP. When it's down, requests to port 5351 will fail.

aartrost commented 8 months ago

Hi Jordan! First off, thank you for your work on this.

I'm seeing this error too, but I think it's because I suspect my setup is talking to the wrong gateway. When I install natpmpc in my lscr.io/linuxserver/transmission docker instance things will not work until I manually specify the gateway IP as seen below:

output of just running natpmpc:

initnatpmp() returned 0 (SUCCESS)
using gateway : 172.31.200.1
sendpublicaddressrequest returned 2 (SUCCESS)
readnatpmpresponseorretry returned -7 (FAILED)
readnatpmpresponseorretry() failed : the gateway does not support nat-pmp
  errno=111 'Connection refused'

vs the output of running natpmpc -g 10.2.0.1:

initnatpmp() returned 0 (SUCCESS)
using gateway : 10.2.0.1
sendpublicaddressrequest returned 2 (SUCCESS)
readnatpmpresponseorretry returned 0 (OK)
Public IP address : xxx.xxx.xxx.xxx
epoch = 8420689
closenatpmp() returned 0 (SUCCESS)

Would it be possible to add an environment variable to specify the gateway port manually? Something like NAT_PMP_GATEWAY=10.2.0.1

Update: Just noticed this mod pulls the gateway ip like so: $(grep nameserver /etc/resolv.conf | awk '{print $2}') which for me resolves to 127.0.0.11 and running natpmpc -g 127.0.0.11 does indeed return Connection refused.

jordanpotter commented 8 months ago

Hey @aartrost , that shouldn't be a problem! Just need to update this line to respect the NAT_PMP_GATEWAY environment variable before relying on the default.

Unfortunately, I won't be able to implement and test this soon. But I'd happily accept a PR!

aartrost commented 8 months ago

I built and published the change above here: aartr/transmission-nat-pmp in case you want to give it a spin. It works well on my end.

SCR-20240308-jgt

jordanpotter commented 8 months ago

Brilliant, thank you for doing that! Just left 1 comment 👍

jordanpotter commented 8 months ago

Excellent work! PR merged 🥳

aartrost commented 8 months ago

Good stuff! For anyone looking to change their nat-pmp gateway IP, this should now do the trick:

-e 'DOCKER_MODS'='jordanpotter/docker-mods:transmission-nat-pmp'
-e 'GATEWAY'='10.2.0.1'