You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is because the default value for config.retry is -1 (infinite retries), and InfluxDB::Client.initialize will only register the code with at_exit that would flush the queue when config.retry > 0. Since the main thread (along with all the spawned worker threads) will exit immediately after pushing data onto the worker queue, all that data will be lost.
Is there any way to have infinite retries and not lose data on exit with the existing code? Adding the following code seems to do the trick:
That way I can have infinite retries during normal operation and then give the main thread one last try to send anything still on the queue when it's exiting. But that's annoying to do everywhere I use influxdb with async: true
Would it make sense to change client.rb from this:
def initialize(database = nil, **opts)
opts[:database] = database if database.is_a? String
@config = InfluxDB::Config.new(opts)
@stopped = false
@writer = find_writer
at_exit { stop! } if config.retry > 0
end
def stop!
writer.worker.stop! if config.async?
@stopped = true
end
to this:
def initialize(database = nil, **opts)
opts[:database] = database if database.is_a? String
@config = InfluxDB::Config.new(opts)
@stopped = false
@writer = find_writer
at_exit { stop! }
end
def stop!
if config.async?
config.retry = 0 if config.retry < 0
writer.worker.stop!
end
@stopped = true
end
That way, if you have async set and a retry greater than or equal to 0, you'll get the cleanup with retry still at that number. If you have async set and retry set to -1, the code will set it to 0 and run the cleanup, just to give the main thread one last chance to write the data.
The text was updated successfully, but these errors were encountered:
Thanks for reporting this. I am on my way to bed, but I will take a look tomorrow. From a first glance, the suggested solution (2) could also be a fix for a sporadically failing test on JRuby.
I need to make sure this doesn't introduce other weirdnesses. Would you mind preparing a PR, so that Travis can perform a first sanity check? That would be great :-)
The following program won't send anything to influxdb:
This is because the default value for
config.retry
is-1
(infinite retries), andInfluxDB::Client.initialize
will only register the code withat_exit
that would flush the queue whenconfig.retry > 0
. Since the main thread (along with all the spawned worker threads) will exit immediately after pushing data onto the worker queue, all that data will be lost.Is there any way to have infinite retries and not lose data on exit with the existing code? Adding the following code seems to do the trick:
That way I can have infinite retries during normal operation and then give the main thread one last try to send anything still on the queue when it's exiting. But that's annoying to do everywhere I use influxdb with
async: true
Would it make sense to change
client.rb
from this:to this:
That way, if you have
async
set and aretry
greater than or equal to0
, you'll get the cleanup withretry
still at that number. If you haveasync
set andretry
set to-1
, the code will set it to0
and run the cleanup, just to give the main thread one last chance to write the data.The text was updated successfully, but these errors were encountered: