James Netherton created CAMEL-27927:
---------------------------------------
Summary: camel-salesforce: a producer call hangs forever when
logging in again after a 401 fails
Key: CAMEL-27927
URL: https://issues.apache.org/jira/browse/CAMEL-27927
Project: Camel
Issue Type: Bug
Components: camel-salesforce
Reporter: James Netherton
Assignee: James Netherton
When a request gets a 401 and logging in again then fails (for example the
credentials stopped working while the application runs: a changed password, a
rotated client secret, a revoked refresh token), the producer never completes.
{{requestBody}} blocks forever instead of failing with a
{{SalesforceException}}, so error handling, redelivery and alerting never see
the failure, and each further request on the 401 path blocks another thread.
{{RestApiManualIT.testRetryFailure}} reproduces it against a scratch org. It
revokes the access token, sets a bad password, and expects a
{{CamelExecutionException}} caused by a {{SalesforceException}} with status
400. The test hangs, and the log ends with:
{noformat}
WARN SalesforceSecurityHandler - Retrying on Salesforce authentication error
[401]: [Unauthorized]
INFO SalesforceSession - Login at Salesforce loginUrl:
https://<instance>/services/oauth2/token
ERROR SalesforceSecurityHandler - Login failed during authentication retry
org.apache.camel.component.salesforce.api.SalesforceException:
{errors:[{"errorCode":"invalid_client",...}],statusCode:400}
{noformat}
Nothing else is logged, and the test is still running 90 seconds later.
Cause, from reading the code:
# CAMEL-24161 (commit 701eb46e477e) made re-logins after a 401 single-flight:
the login runs on the worker pool through {{session.login(oldToken)}}, so
concurrent 401s share one token request. When that login fails,
{{SalesforceSecurityHandler.retryLogin()}} calls
{{forwardFailureComplete(request, null, null, e)}}, so the {{Result}} passed to
the response listener has no response.
# The listener in {{AbstractClientBase}} starts {{onComplete}} with
{{determineHeadersFrom(result.getResponse())}}, which calls
{{response.getHeaders()}} and throws a {{NullPointerException}}.
# Jetty catches the exception while notifying the listener, so
{{callback.onResponse}} is never called and the exchange never completes.
Possible fix, keeping the single-flight login and the other changes of
CAMEL-24161:
* Make {{AbstractClientBase}} handle a missing response (no headers), so the
{{SalesforceException}} of the failed login reaches the callback through the
existing {{failure instanceof SalesforceException}} branch. It already carries
status 400.
* Optionally pass the original 401 response from {{retryLogin}} to
{{forwardFailureComplete}}.
The ManualIT does not run in CI, so the fix should come with a unit test that
stubs a 401 and a failing login, without a Salesforce org.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)