oscartbeaumont / netlify-dynamic-dns

A Dynamic DNS Client For Netlify Managed DNS
MIT License
62 stars 19 forks source link

Multiple A records being created for same subdomain #18

Open rahul003 opened 3 years ago

rahul003 commented 3 years ago

How do I prevent multiple records from being created? I'm running like this. This only happens some times. Unable to figure out when it replaces the IP vs when it creates a new entry

NDDNS_IPv6_ENABLED=false /sgt/projects/dyndns/nddns_Linux_Arm64 --accesstoken `cat /sgt/projects/dyndns/netlify.key` --zone $DOMAIN.com --record $rec --interval 0

oscartbeaumont commented 3 years ago

I am unable to reproduce this, if you can provide an example set of commands that can reproduce it I can have a look overwise from my end everything seems to be working fine.

rahul003 commented 3 years ago

Could this happen if I have multiple instances of command in parallel?

oscartbeaumont commented 3 years ago

I am fairly certain multiple instances could result in this behaviour, however they would have to be pointing at the same zone and record. This however is a limitation of Netlify.

The technical explanation as to why is that Netlify DNS records are idempotent (can't be changed), hence this project finds and delete the old record and then creates a new one every time it detects your IP address has changed. Theoretically, if you had two instances of the app running at the same time and they ran the update at the same time (highly unlikely but possible) they could run both send the delete command (although one of them would possibly fail) and then both create a new record.

rahul003 commented 3 years ago

Alright, I think this might have happened

neugartf commented 3 years ago

I must say, I also ran into this with the v3.x. Started a cron with a new reboot so I'm quite confident that there was just one instance running 🤔.

image
oscartbeaumont commented 3 years ago

Can you see anything in the console output of netlify-dynamic-dns? Maybe a network failure is occurring or something, I'm not sure. Without being able to reproduce this reliably makes it hard to fix.

neugartf commented 3 years ago

Just checkd my syslog. Doesn't seem to look like they is an error. TBH I'm not too sure if this would logged anyway. I actually had a cron every 5 minutes, not after reboot. Sorry!

CRON[21968]: (pi) CMD (/usr/local/bin/nddns -accesstoken *** -zone neugartf.com -record string -ipv6=false)

neugartf commented 3 years ago

I had a closer look, but didn't find anything either (neither in their API nor your code)

What I see might be a general issue, is sanitizing the input args: /usr/local/bin/nddns -accesstoken *** -zone " neugartf.com" -record matrix -ipv6=false I was able to create an infinite loop by adding a white space to the zone

image
rahul003 commented 3 years ago

@neugartf You might want to deactivate and change your access token as it's visible in the screenshot.

neugartf commented 3 years ago

@rahul003 Thanks for the warning! 🤗

oscartbeaumont commented 3 years ago

@neugartf I don't do any validation of the arguments so that I don't introduce any issues if my validation logic doesn't match Netlify's but when I get some time I might make the app exit if the first update upon startup fails. This should prevent the loop as you have found above and act as a way to use Netlify to validate the arguments. I have stopped using this project (due to not having firewall access where I currently live) but when I get a minute I will add detailed logging and see if I can deploy it somewhere as it might help to determine what is causing this issue. If you are interested in fixing it yourself have a look over the codebase. If anyone has a look at the code and has any questions feel free to ask them here or send me an email.