[google-cloud-datastore] timeout option has no effect: per-RPC defaults override it (same as #14050)

Đang mở
#36,632 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

api: datastore priority: p2 type: bug

The timeout option documented in OVERVIEW.md ("Configuring timeout") is accepted by Google::Cloud::Datastore.new but never applied to requests. Every RPC is sent with the 60 s RPC-specific default from google-cloud-datastore-v1.

This is the same problem reported for Pub/Sub in #14050 and fixed there in #14405 ("Propagate timeout to client RPC configs"). The Datastore library didn't get the equivalent change.

Environment details
  • OS: macOS
  • Ruby version: 3.4.9
  • Gem name and version: google-cloud-datastore 2.14.0, google-cloud-datastore-v1 1.6.0, gapic-common 1.3.0

The code involved is unchanged on main.

Steps to reproduce
  1. Create a dataset with timeout: 5.
  2. Make any request.
  3. The request is sent with a 60 s timeout, not 5 s.
Code example
require "google/cloud/datastore"

ENV["DATASTORE_EMULATOR_HOST"] = "localhost:8081" # no server needed; the RPC is intercepted

datastore = Google::Cloud::Datastore.new project_id: "my-project", timeout: 5
client = datastore.service.service # Google::Cloud::Datastore::V1::Datastore::Client
puts "client config.timeout:      #{client.configure.timeout.inspect}"
puts "client config.rpcs.commit:  #{client.configure.rpcs.commit.timeout.inspect}"

stub = client.instance_variable_get :@datastore_stub
stub.define_singleton_method :call_rpc do |method, _request, options:|
  puts "#{method} sent with timeout: #{options.timeout.inspect}"
  raise "stop"
end

[-> { datastore.save datastore.entity("Task", "a") },
 -> { datastore.find "Task", "a" },
 -> { datastore.allocate_ids datastore.key("Task"), 1 }].each do |call|
  call.call
rescue StandardError
  nil
end

Output:

client config.timeout:      5
client config.rpcs.commit:  60.0
commit sent with timeout: 60.0
lookup sent with timeout: 60.0
allocate_ids sent with timeout: 60.0
Cause

Google::Cloud::Datastore::Service#service sets only the client-wide config.timeout (service.rb:48). The generated client sets rpcs.<rpc>.timeout = 60.0 for every Datastore RPC and applies it first:

options.apply_defaults timeout: @config.rpcs.lookup.timeout, ...  # 60.0
options.apply_defaults timeout: @config.timeout, ...              # 5

Gapic::CallOptions#apply_defaults only fills an empty value (@timeout ||= timeout), so the client-wide timeout is never used.

Suggested fix

Apply the same change as #14405 to google-cloud-datastore: when a timeout is given, copy it to each config.rpcs.*.timeout in Service#service. Failing that, update OVERVIEW.md to say the option has no effect and document the per-RPC workaround (Google::Cloud::Datastore::V1::Datastore::Client.configure { |c| c.rpcs.commit.timeout = ... }).

Ngôn ngữ chính
Ruby
Star
1.4k
Fork
581
Merge trung bình
1 ngày 22 giờ
Pull request đã merge (30 ngày)
69

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của googleapis/google-cloud-ruby

Tất cả issue của googleapis/google-cloud-ruby

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.