Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Customer creation fails with VIES VAT ratelimit #2911

Open
andrasszommer opened this issue Dec 4, 2024 · 1 comment
Open

[BUG]: Customer creation fails with VIES VAT ratelimit #2911

andrasszommer opened this issue Dec 4, 2024 · 1 comment

Comments

@andrasszommer
Copy link

Describe the bug
Since the latest 1.16.0 release (but may not be related to the version this way) when I start up a new Lago instance (with multiple already existing customers) everything seems fine until I want to create a new customer.
Once, I try to create a new customer through the API (which may related to the timing after the startup, based on its a ratelimit error) the customer creation fails with Valvat::RateLimitError. Some time later I can create the customer without any problem.

To Reproduce
Steps to reproduce the behavior:

  1. Make several VAT checks (I think the startup process may check the existing customers or something)
  2. After that instantly try to create customers through the API
  3. Valvat::RateLimitError should throw a 500 error on the customer endpoint

Expected behavior
The VAT check should not be a sync process, instead it should run in the background and should not interfere with the customer creation endpoint.

Additional context

INFO -- : [c5f6faa5-adfe-4440-8b8f-7405fd9e04ea] {"method":"POST","path":"/api/v1/customers","format":"json","controller":"Api::V1::CustomersController","action":"create","status":500,"allocations":81407,"duration":430.22,"view":0.0,"db":33.36,"ddsource":"ruby","params":{"customer":{"external_id":"01je6r2hyc1q7bdha5vkpbs2r3","lago_id":null,"slug":null,"address_line1":"Address","address_line2":null,"city":"Berlin","country":"DE","currency":"EUR","email":null,"legal_name":"Example","legal_number":null,"tax_identification_number":"DE111222","logo_url":null,"name":"My Customer","phone":null,"state":null,"timezone":null,"url":null,"zipcode":"11111","metadata":[]}},"organization_id":"8cd18b2a-3a7e-42fa-889b-9e4321642c0f","trace_id":"00000000000000000000000000000000","span_id":"0000000000000000"}
lago-api      | E, [2024-12-03T17:11:28.404414 #21] ERROR -- : [c5f6faa5-adfe-4440-8b8f-7405fd9e04ea]
lago-api      | [c5f6faa5-adfe-4440-8b8f-7405fd9e04ea] Valvat::RateLimitError (The VIES web service returned the error: MS_MAX_CONCURRENT_REQ):
lago-api      | [c5f6faa5-adfe-4440-8b8f-7405fd9e04ea]
lago-api      | [c5f6faa5-adfe-4440-8b8f-7405fd9e04ea] app/services/customers/eu_auto_taxes_service.rb:27:in `vies_check'
lago-api      | [c5f6faa5-adfe-4440-8b8f-7405fd9e04ea] app/services/customers/eu_auto_taxes_service.rb:15:in `call'
lago-api      | [c5f6faa5-adfe-4440-8b8f-7405fd9e04ea] app/services/base_service.rb:151:in `block in call'
lago-api      | [c5f6faa5-adfe-4440-8b8f-7405fd9e04ea] app/services/base_service.rb:150:in `call'
lago-api      | [c5f6faa5-adfe-4440-8b8f-7405fd9e04ea] app/services/customers/create_service.rb:74:in `block in create_from_api'
lago-api      | [c5f6faa5-adfe-4440-8b8f-7405fd9e04ea] app/services/customers/create_service.rb:33:in `create_from_api'
lago-worker   | /usr/local/lib/ruby/3.3.0/net/http.rb:1569:in `start'
lago-worker   | /usr/local/lib/ruby/3.3.0/net/http.rb:2297:in `request'
lago-worker   | /usr/local/bundle/gems/newrelic_rpm-9.12.0/lib/new_relic/agent/instrumentation/net_http/prepend.rb:15:in `block in request'
lago-worker   | /usr/local/bundle/gems/newrelic_rpm-9.12.0/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb:30:in `block (2 levels) in request_with_tracing'
lago-worker   | /usr/local/bundle/gems/newrelic_rpm-9.12.0/lib/new_relic/agent/tracer.rb:357:in `capture_segment_error'
lago-worker   | /usr/local/bundle/gems/newrelic_rpm-9.12.0/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb:29:in `block in request_with_tracing'
lago-worker   | /usr/local/bundle/gems/newrelic_rpm-9.12.0/lib/new_relic/agent.rb:655:in `disable_all_tracing'
lago-worker   | /usr/local/bundle/gems/newrelic_rpm-9.12.0/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb:28:in `request_with_tracing'
lago-worker   | /usr/local/bundle/gems/newrelic_rpm-9.12.0/lib/new_relic/agent/instrumentation/net_http/prepend.rb:15:in `request'
lago-worker   | /usr/local/bundle/gems/sentry-ruby-5.18.2/lib/sentry/net/http.rb:31:in `request'
lago-worker   | /app/lib/lago_http_client/lago_http_client/client.rb:44:in `post_with_response'
lago-worker   | /app/app/services/webhooks/send_http_service.rb:15:in `call'
lago-worker   | /app/app/services/base_service.rb:151:in `block in call'
lago-worker   | /usr/local/bundle/gems/opentelemetry-api-1.3.0/lib/opentelemetry/trace/tracer.rb:37:in `block in in_span'
lago-worker   | /usr/local/bundle/gems/opentelemetry-api-1.3.0/lib/opentelemetry/trace.rb:70:in `block in with_span'
lago-worker   | /usr/local/bundle/gems/opentelemetry-api-1.3.0/lib/opentelemetry/context.rb:87:in `with_value'
lago-api      | [c5f6faa5-adfe-4440-8b8f-7405fd9e04ea] app/controllers/api/v1/customers_controller.rb:8:in `create'
lago-worker   | /usr/local/bundle/gems/opentelemetry-api-1.3.0/lib/opentelemetry/trace.rb:70:in `with_span'
lago-worker   | /usr/local/bundle/gems/opentelemetry-api-1.3.0/lib/opentelemetry/trace/tracer.rb:37:in `in_span'
lago-api      | I, [2024-12-03T17:11:29.240956 #21]  INFO -- : [ab3eaf1b-e34a-4553-84aa-92baae1e38c9] {"method":"GET","path":"/health","format":"*/*","controller":"ApplicationController","action":"health","status":200,"allocations":161,"duration":1.43,"view":0.15,"db":0.66,"ddsource":"ruby","params":{},"organization_id":null,"trace_id":"00000000000000000000000000000000","span_id":"0000000000000000"}
lago-worker   | /app/app/services/base_service.rb:150:in `call'
lago-worker   | /app/app/jobs/send_http_webhook_job.rb:5:in `perform'

Version

  • Lago: v1.6.0+
@jdenquin
Copy link
Contributor

jdenquin commented Dec 4, 2024

Hello @andrasszommer

We are aware of it but thanks for catching it!
It's actually a sync call because some users may create invoice directly just after the customer, it may lead to bad VAT being applied (or no VAT at all).

As a very quick fix I would recommend you to catch this error and retry this call when you have this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants