lib/mongo/grid/stream/read.rb in mongo-2.20.1 vs lib/mongo/grid/stream/read.rb in mongo-2.21.0
- old
+ new
@@ -57,10 +57,16 @@
@fs = fs
@options = options.dup
@file_id = @options.delete(:file_id)
@options.freeze
@open = true
+ @timeout_holder = CsotTimeoutHolder.new(
+ operation_timeouts: {
+ operation_timeout_ms: options[:timeout_ms],
+ inherited_timeout_ms: fs.database.timeout_ms
+ }
+ )
end
# Iterate through chunk data streamed from the FSBucket.
#
# @example Iterate through the chunk data.
@@ -176,11 +182,15 @@
# @return [ File::Info ] The file information object.
#
# @since 2.1.0
def file_info
@file_info ||= begin
- doc = options[:file_info_doc] || fs.files_collection.find(_id: file_id).first
+ doc = options[:file_info_doc] ||
+ fs.files_collection.find(
+ { _id: file_id },
+ { timeout_ms: @timeout_holder.remaining_timeout_ms! }
+ ).first
if doc
File::Info.new(Options::Mapper.transform(doc, File::Info::MAPPINGS.invert))
else
nil
end
@@ -206,9 +216,13 @@
@view ||= begin
opts = if read_preference
options.merge(read: read_preference)
else
options
+ end
+ if @timeout_holder.csot?
+ opts[:timeout_ms] = @timeout_holder.remaining_timeout_ms!
+ opts[:timeout_mode] = :cursor_lifetime
end
fs.chunks_collection.find({ :files_id => file_id }, opts).sort(:n => 1)
end
end