caronc / apprise-api

A lightweight REST framework that wraps the Apprise Notification Library
https://hub.docker.com/r/caronc/apprise
MIT License
580 stars 50 forks source link

Apprise & IPv6 #127

Closed acaranta closed 9 months ago

acaranta commented 11 months ago

This is a report/information of a "bug" that may impact others and may help to correct the situation :)

:lady_beetle: apprise docker image does not work correctly if ipv6 is enabled Hi! I am running apprise using the docker image (caronc/apprise:latest) on my server, on which docker has ipv6 enabled to provide connectivity on the docker network the container runs in. Apprise seems to start properly, and some notifications (ie : pushbullet was tested ✅ ) works, but other simply fail weirdly (ie : telegram ❌).

I searched for quite some time, and the logs I was getting for a telegram notification were (infos has been anonymized ^^) :

Aug 14 09:35:02 dockerhost apprise_1[2308]: 2023/08/14 07:35:02 [error] 19#19: *47 connect() failed (111: Connection refused) while connecting to upstream, client: <CLIENTIP>, server: , request: "POST /notify/mycfg HTTP/1.1", upstream: "http://[::1]:8080/notify/mycfg", host: "apprise.example.com" 
Aug 14 09:35:02 dockerhost apprise_1[2308]: 2023/08/14 07:35:02 [warn] 19#19: *47 upstream server temporarily disabled while connecting to upstream, client: <CLIENTIP>, server: , request: "POST /notify/mycfg HTTP/1.1", upstream: "http://[::1]:8080/notify/mycfg", host: "apprise.example.com"                                                                      
Aug 14 09:35:02 dockerhost apprise_1[2308]: 2023-08-14 02:35:02,831 [INFO] apprise: Loaded 1 entries from memory://                                                                                                                                                                                                                                                               
Aug 14 09:35:06 dockerhost apprise_1[2308]: 2023-08-14 02:35:06,943 [WARNING] apprise: A connection error occurred sending Telegram:<CHATID> notification.                                                                                                                                                                                                                       
Aug 14 09:35:06 dockerhost apprise_1[2308]: 2023-08-14 02:35:06,945 [WARNING] django.request: Failed Dependency: /notify/mycfg                                                                                                                                                                                                                                                  
Aug 14 09:35:06 dockerhost apprise_1[2308]: <CLIENTIP> - - [14/Aug/2023:07:35:06 +0000] "POST /notify/mycfg HTTP/1.1" 424 56 "-" "got (https://github.com/sindresorhus/got)"   

I finally understood what was going on :

When ipv6 is enabled, apprises starts and it processes listens on port 8000, and 8080 on ipv4. Which is ok... but since ipv6 is available in the Apprise container, when it internally tries reaching it's 8080 port, it defaults to using "ipv6 localhost" (aka [::1]) ... and fails without much clear error.

Now this is a bug, in that ipv6 is clearly (for now I guess) not supported, but if activated, breaks apprise.

So as a working fix, I found that everything goes back to normal, if ipv6 is de-activated for that container, for instance in my compose definition for apprise, adding :

    sysctls:
      - net.ipv6.conf.all.disable_ipv6=1        

Hope, maybe one day ipv6 will be supprted 🤗 but in the meantime, this may help others facing similar issues ^^

caronc commented 11 months ago

I'm not sure if this a bug per say, it shows that `ipv6' is experimental with docker; see here image

If you think nginx should be updated to also listen on an ipv6 port, it may break it for ipv4 users and the out-of-box docker working environment.

but i'm open to suggestions; can you point me to other containers that work for you right out of the box? Maybe i'm overthinking this? :slightly_smiling_face:

acaranta commented 11 months ago

To be honest, I am using ipv6 for docker and sub networks for months (I don't even use the 'experimental' flag ... wasn't mentionned when I started like 1 or 2 years ao hehe).

Maybe I shouldn't have classified this issue as a "bug" tho. I do not require you to force ipv6 on nginx and such things, especially since the number of users using ipv6 that way seem very low 😄 I was just providing some solution in case ppl had the same trouble :)

Now, enabling ipv6 for apprise may indeed imply more testing and stuff, so I'd say don't focus at all on that for now I guess :)

on the containers working with ipv6, let me see ..

TL;DR : don't worry too much about this ""bug"" I raised, unless many other users make the same request, keep the great work on what you do currently :)

caronc commented 11 months ago

It'll take about 30min to rebuild the :edge version of Apprise on Docker, but you should be able to try out the ipv6 version with the tiny change i made. I would be curious to hear your feedback. :slightly_smiling_face:

acaranta commented 10 months ago

Gonna check asap (been busy lately, sorry for the delayed responses) ^^

acaranta commented 10 months ago

ok so .... I tested several things ... what you added was not enough ... had to also modify gunicorn start command to allow it to listent on ipv4 and ipv6. now this allows apprise to be reachable and working correctly ... except .... for some services.

I tested using my current configuration, and sending a message while ipv6 is active :

I am working on trying to see why, and if I can find a solution I will gladly propose a PR :)

I also have to retest the whole setup with ipv4 only, in order to check if it breaks anything (that would be bad for normal users :) )

I'll keep in touch asap :)

acaranta commented 10 months ago

Just tested disabling ipv6 for this container, it still works properly ... and telegram works again too lol ... so I guess I'll have to dig deeper 🙈

caronc commented 10 months ago

I was hoping the :edge release would work for you with IPV6. I'll also keep digging then; especially if comparable services are working fine, i would think it should work for us too

acaranta commented 10 months ago

AHAH nervermind ... nothing wrong with your code indeed ... it's just that telegram ahev, as it seems, problems with ipv6 on their servers ... they have an AAAA record for telegram.org ... BUT the address doesn't work lol it just timesout ....

soooo telegram is not working when ipv6 is active, since your code does exactly what it should do : check ipv6 connectivity (since it's enabled) and uses that since telegram offers an ipv6 record. But it fails cause telegram has a problem (found several cases on the web about this issue).

acaranta commented 10 months ago

so changes I made to enable ipv6 (regardless of telegram own issues on their side) : in apprise_api/etc/supervisord.conf , changed the supervisord gunicorn startup command so that it listens dual stack :

command=gunicorn -c /opt/apprise/webapp/gunicorn.conf.py -b '[::]:8080' --worker-tmp-dir /dev/shm core.wsgi

And, but I am not much sure this one is needed (still, at least it reflects the whoel dual stack idea :) ), in apprise_api/gunicorn.conf.py I changed the port bindind to same dual stack notation :

bind = [
    '[::]:8000',
] 
caronc commented 10 months ago

Let me know if this is resolved now; your suggested changes were pushed to the latest version of the API

acaranta commented 10 months ago

I'll Recheck asap :)

caronc commented 9 months ago

Any update; is this working for you?

acaranta commented 9 months ago

Been having some troubles lately, gonna check that today, promise ^^

acaranta commented 9 months ago

OK, sorry for the huge delay ... tested against master branch, every thing works as it did in ipv4, and when switched to dual stack v4/v6 it walso responds properly as expected ! THX :)

I guess we can close this issues :)