Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MaxLifeTime configuration for HikariCP to traccar.xml #5255

Open
ghhv opened this issue Jan 24, 2024 · 1 comment
Open

Add MaxLifeTime configuration for HikariCP to traccar.xml #5255

ghhv opened this issue Jan 24, 2024 · 1 comment

Comments

@ghhv
Copy link

ghhv commented Jan 24, 2024

Is your feature request related to a problem? Please describe.
When using Traccar with Docker Swarm, there is a known issue with TCP timeouts between containers of 15mins. This affects other Java based apps like Moby and some Kubernetes installations and any database connection like Postgresql or Mysql.
In Traccar, this 15min limit is less than the default HikariCP MaxLifeTime value of 30mins and therefore installations using Docker Swarm constantly get this warning:
WARN: HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@NNN (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
More background below.

Describe the solution you'd like
Add the option to configure HikariCP MaxLifetime to traccar.xml configuration like so:

<entry key='database.maxLifeTime'>[new_value]</entry>

with this added to Keys.java

 public static final ConfigKey<Integer> DATABASE_MAX_LIFE_TIME = new IntegerConfigKey(
            "database.maxLifeTime",
            List.of(KeyType.CONFIG));

And this added to DatabaseModule.java

 int maxLifeTime= config.getInteger(Keys.DATABASE_MAX_LIFE_TIME );
        if (maxLifeTime!= 0) {
            hikariConfig.setMaxLifetime(maxLifeTime);
        }

And anything else I'm not aware of to make this work. See IdleTimeOut below.

Describe alternatives you've considered
I've tested changing every other timeout without any resolution.
A suggested workaround from here does not work for Traccar as you need to expose specific ports which is incompatible with opening ports for specific GPS devices.

EndpointSpec: port published with ingress mode can't be used with dnsrr mode

Additional context
Other (mostly non-Traccar) references to this issue are listed below:
docker swarm configurations there is an internal TCP idle timeout at 15 minutes

[Docker Swarm: TCP connection between containers disconnected after being idle for about 900 seconds]
(https://github.com/moby/moby/issues/37822#top)](https://github.com/moby/moby/issues/37822)

TCP timeout that occurs only in Docker Swarm, not simple “docker run”

MaxLifeTime is also subject to the IdleTimeout but this is hard-coded in Traccar - this may need to be added to the config as well.
hikariConfig.setIdleTimeout(600000);

Max lifetime must be less than all other timeouts

This is a known issue with HikariCP and Docker/Kubernetes

Issue solved by setting maxLifetime to 10 minutes

Another reference to this same issue with Moby

I mentioned this issue a year ago with some of these same references in the Traccar forum

Anton referenced a fix for this issue 8 months ago but there's still no way to change MaxLifeTime as shown above.

HikariCP documentation to set MaxLifeTime

@tananaev
Copy link
Member

Feel free to send a pull request.

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

No branches or pull requests

2 participants