Skip to content
This repository has been archived by the owner on Mar 12, 2019. It is now read-only.

PostgreSQL backend should attempt to reconnect to the database #269

Closed
brocaar opened this issue Jun 23, 2017 · 17 comments · Fixed by #339
Closed

PostgreSQL backend should attempt to reconnect to the database #269

brocaar opened this issue Jun 23, 2017 · 17 comments · Fixed by #339

Comments

@brocaar
Copy link
Contributor

brocaar commented Jun 23, 2017

Hi, thanks again for your project. I think it is a great addition to Mosquitto!

However, I noticed on issue. I'm using the plugin with a PostgreSQL database. I just rebooted one of my servers and noticed that Mosquitto was not running after the reboot. Looking at the logs, it simply stopped with the following error:

|-- We were unable to connect to the database
|-- *** ABORT.

The reason is that Mosquitto was started before the PostgreSQL database was started. I think it would be better to put the database connection in a loop and log when it can't connect, but keep Mosquitto running. That way, it would recover eventually.

@jasiek
Copy link
Contributor

jasiek commented Jul 5, 2017

I think this would be useful - reconnect to the database if the connection is dead.

@brocaar
Copy link
Contributor Author

brocaar commented Jul 6, 2017

That, and when I reboot the server, Mosquitto is started before PostgreSQL. This means that after a boot I have to start Mosquitto manually as it could not start at first.

Hopefully this can be changed so that a broken db connection will never result into Mosquitto aborting.

@jasiek
Copy link
Contributor

jasiek commented Jul 6, 2017

@jpmens How do these plugins work? Is there a plugin instance per thread within mosquitto or is there a single instance which is shared?

@jpmens
Copy link
Owner

jpmens commented Jul 6, 2017

@brocaar the order of service starts (mosquitto, pgsql) is set up by your packages/distribution and beyond the scope of this project.

@jpmens
Copy link
Owner

jpmens commented Jul 6, 2017

@jasiek there's a single shared instance.

@jpmens
Copy link
Owner

jpmens commented Jul 6, 2017

I agree that in case the database goes down (short restart), we should attempt to reconnect to the backend database if possible, and I'll take a pull-request which does that.

But please note again: this should not be required to cater for Mosquitto launches before database.

@jpmens jpmens changed the title PostgreSQL / DB dependency issue on server boot PostgreSQL backend should attempt to reconnect to the database Jul 6, 2017
@jasiek
Copy link
Contributor

jasiek commented Jul 6, 2017

I'll try to put something together in the next few days.

@tidanilocarvalho
Copy link

Hi, I am using the plugin, this is awesome, but the same problem happen when the database is restarted, I like would this feature reconnect database too.

@tmcdos
Copy link

tmcdos commented Aug 3, 2017

This plugin is amazing but I also think the auto-reconnect feature is highly desirable. I vote for it.

@tidanilocarvalho
Copy link

I vote for it too, and how you can see, there are many testers to help.

@jpmens
Copy link
Owner

jpmens commented Aug 3, 2017

It's grand you're all voting for it, so I'll add my vote as well.

Now we just need somebody to write the code, eh? ;-)

@tidanilocarvalho
Copy link

Well, I just tried help writing here about my point, but, I can help write code too, we are using heavily your plugin.

@jasiek
Copy link
Contributor

jasiek commented Aug 3, 2017

If only there was someone to do the actual work...

It's on my list, but pretty low. I might get around to it in ca 3 weeks.

@jklimke
Copy link

jklimke commented Feb 7, 2018

Is there any progress here?

@jasiek
Copy link
Contributor

jasiek commented Feb 7, 2018

Not really. Feel free to pick this up.

@jklimke
Copy link

jklimke commented Apr 9, 2018

Actually i gave an implementation a try. Since PQreset(conn) tries to restore the database connection, the database connection should now be restored after being lost. It would be nice if anyone could have a look at the pull request, since this missing feature was killing our mosquitto each time when an database upgrade was happening.

@tidanilocarvalho
Copy link

Hi, how are you guys?

I know that this topic was closed, but, I've tested the new implementation and it is work very well, perfectly!!!

Thanks a lot!!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants