From e338355a7d6dafa1edc8718cfbf4858edf521d3a Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Fri, 10 Apr 2026 11:38:33 -0600 Subject: [PATCH 1/2] remove redundant operator definitions (TODO cleanup) --- lib/mongo/cluster_time.rb | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/lib/mongo/cluster_time.rb b/lib/mongo/cluster_time.rb index ccfd1a5c68..385ac908dd 100644 --- a/lib/mongo/cluster_time.rb +++ b/lib/mongo/cluster_time.rb @@ -26,6 +26,8 @@ module Mongo # # @api private class ClusterTime < BSON::Document + include Comparable + def initialize(elements = nil) super @@ -62,25 +64,6 @@ def <=>(other) end end - # Older Rubies do not implement other logical operators through <=>. - # TODO revise whether these methods are needed when - # https://jira.mongodb.org/browse/RUBY-1622 is implemented. - def >=(other) - (self <=> other) != -1 - end - - def >(other) - (self <=> other) == 1 - end - - def <=(other) - (self <=> other) != 1 - end - - def <(other) - (self <=> other) == -1 - end - # Compares two ClusterTime instances by comparing their timestamps. def ==(other) if self['clusterTime'] && other['clusterTime'] && From fe0c6ec67068646d64c06e9fefdb12ad4b54a29e Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Fri, 10 Apr 2026 14:29:27 -0600 Subject: [PATCH 2/2] cleaning up some long-standing TODO comments --- lib/mongo/cluster/reapers/cursor_reaper.rb | 7 +++--- lib/mongo/operation/result.rb | 3 --- lib/mongo/protocol/msg.rb | 2 -- lib/mongo/socket/ocsp_cache.rb | 2 +- lib/mongo/socket/ocsp_verifier.rb | 26 +++++++++++++++------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/mongo/cluster/reapers/cursor_reaper.rb b/lib/mongo/cluster/reapers/cursor_reaper.rb index 0b4727d76d..cf1bd0e0e1 100644 --- a/lib/mongo/cluster/reapers/cursor_reaper.rb +++ b/lib/mongo/cluster/reapers/cursor_reaper.rb @@ -177,9 +177,10 @@ def kill_cursors end unless server - # TODO: We currently don't have a server for the address that the - # cursor is associated with. We should leave the cursor in the - # queue to be killed at a later time (when the server comes back). + # The server for this cursor has gone away --- maybe temporarily, + # maybe permanently, but we can't know. To prevent connections from + # leaking in the case of a permanent failure, we'll just silently + # drop this killspec and move on. next end diff --git a/lib/mongo/operation/result.rb b/lib/mongo/operation/result.rb index 7501322174..7facea167f 100644 --- a/lib/mongo/operation/result.rb +++ b/lib/mongo/operation/result.rb @@ -104,9 +104,6 @@ class Result def initialize(replies, connection_description = nil, connection_global_id = nil, context: nil, connection: nil) @context = context - # TODO: older versions of MongoDB (2.4 and below?) could sometimes end - # up with nil here, which indicated an unackowledged write. Is that - # still the case? Can we simplify this? return unless replies if replies.is_a?(Array) diff --git a/lib/mongo/protocol/msg.rb b/lib/mongo/protocol/msg.rb index 010846c776..7866e6a24c 100644 --- a/lib/mongo/protocol/msg.rb +++ b/lib/mongo/protocol/msg.rb @@ -208,8 +208,6 @@ def documents # @return [ Mongo::Protocol::Msg ] The encrypted message, or the original # message if encryption was not possible or necessary. def maybe_encrypt(connection, context) - # TODO: verify compression happens later, i.e. when this method runs - # the message is not compressed. if context.encrypt? if connection.description.max_wire_version < 8 raise Error::CryptError.new( diff --git a/lib/mongo/socket/ocsp_cache.rb b/lib/mongo/socket/ocsp_cache.rb index 1eac665ebc..a99a5cd8f1 100644 --- a/lib/mongo/socket/ocsp_cache.rb +++ b/lib/mongo/socket/ocsp_cache.rb @@ -19,7 +19,7 @@ class Socket # This module caches OCSP responses for their indicated validity time. # # The key is the CertificateId used for the OCSP request. - # The value is the SingleResponse. + # The value is an OcspVerifier::Response. # # @api private module OcspCache diff --git a/lib/mongo/socket/ocsp_verifier.rb b/lib/mongo/socket/ocsp_verifier.rb index d7ac57ee56..db5d20572e 100644 --- a/lib/mongo/socket/ocsp_verifier.rb +++ b/lib/mongo/socket/ocsp_verifier.rb @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +require 'delegate' + module Net autoload :HTTP, 'net/http' end @@ -31,6 +33,19 @@ class Socket # # @api private class OcspVerifier + # Wraps OpenSSL::OCSP::SingleResponse with the responder URI that supplied it. + # + # @api private + class Response < SimpleDelegator + attr_reader :uri, :original_uri + + def initialize(single_response, uri, original_uri) + super(single_response) + @uri = uri + @original_uri = original_uri + end + end + include Loggable # @param [ String ] host_name The host name being verified, for @@ -228,18 +243,13 @@ def verify_one_responder(uri) return false end - resp = resp.find_response(cert_id) - unless resp + single_response = resp.find_response(cert_id) + unless single_response @resp_errors << "OCSP response from #{report_uri(original_uri, uri)} did not include information about the requested certificate" return false end - # TODO: make a new class instead of patching the stdlib one? - resp.instance_variable_set(:@uri, uri) - resp.instance_variable_set(:@original_uri, original_uri) - class << resp - attr_reader :uri, :original_uri - end + resp = Response.new(single_response, uri, original_uri) unless resp.check_validity @resp_errors << "OCSP response from #{report_uri(original_uri,