mirror of
https://github.com/meineerde/rackstash.git
synced 2026-02-10 20:55:18 +00:00
Create new fields, tags and message objects on Buffer#clear
This helps in ensuring thread-safety when flushing unbuffered Buffers. Previously, it was possibly for client code to still hold references to fields on a flushed and cleared buffer, potentially resulting in unintended side-effects if the client code was not aware that the buffer was cleared. By creating ompletely new object instances, existing references only point to data from before the clear. This ensures a clean cut.
This commit is contained in:
parent
0edcce37c7
commit
7e452b630a
@ -76,10 +76,8 @@ module Rackstash
|
||||
@buffering = !!buffering
|
||||
@allow_empty = !!allow_empty
|
||||
|
||||
@messages = []
|
||||
@fields = Rackstash::Fields::Hash.new(forbidden_keys: FORBIDDEN_FIELDS)
|
||||
@tags = Rackstash::Fields::Tags.new
|
||||
@timestamp = nil
|
||||
# initialize the internal data structures for fields, tags, ...
|
||||
clear
|
||||
end
|
||||
|
||||
# Add a new message to the buffer. This will mark the current buffer as
|
||||
@ -130,9 +128,9 @@ module Rackstash
|
||||
#
|
||||
# @return [self]
|
||||
def clear
|
||||
@messages.clear
|
||||
@fields.clear
|
||||
@tags.clear
|
||||
@messages = []
|
||||
@fields = Rackstash::Fields::Hash.new(forbidden_keys: FORBIDDEN_FIELDS)
|
||||
@tags = Rackstash::Fields::Tags.new
|
||||
@timestamp = nil
|
||||
|
||||
self
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user