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

Intermittent 501 Not Implemented Error Due to Unexpected 'offsetGet' Method in Guzzle Requests #3179

Open
mvn-trungtran-dn opened this issue Sep 14, 2023 · 4 comments
Labels
lifecycle/stale No activity for a long time

Comments

@mvn-trungtran-dn
Copy link

mvn-trungtran-dn commented Sep 14, 2023

Guzzle version(s) affected: 6.3.3
PHP version: 7.2.34
cURL version: 7.74.0

Description
I'm encountering an issue with Guzzle where it appears to be attempting to make an HTTP request using the offsetGet method, which is not a standard HTTP method. This results in a 501 Not Implemented response from the server. The issue occurs intermittently on specific ECS instances, and all instances are running the same source code.

How to reproduce
The issue is intermittent and doesn't occur consistently, but here's a rough outline of how it can be observed:

  • Set up an environment with multiple ECS instances running the same source code and Guzzle configuration.

  • Occasionally, on one of the ECS instances, when making an HTTP request using Guzzle, the request may be incorrectly using the offsetGet method instead of a valid HTTP method.

  • This incorrect request results in a 501 Not Implemented response from the server is trigger from this code

       $client = new Client([
            'base_uri' => $this->request->getBaseUri(),
            'headers' => $this->request->getHeaders(),
        ]);
        $options = array_merge($this->request->getParams(), ['timeout' => env('TIMEOUT'), 'connect_timeout' => env('CONNECT_TIMEOUT')]);
        $response = $client->request(
            $this->request->getMethod(),
            $this->request->getUri(),
            $options
        );

Possible Solution
I don't have a specific solution at this time, as the issue is intermittent and doesn't seem to be directly related to the source code or Guzzle configuration. It may require further investigation to identify the root cause.

Additional context

  • The issue occurs on specific ECS instances, and all instances are running the same source code and configuration.
  • The issue does not consistently occur and seems to be related to a specific environment or configuration.
  • The GuzzleHttp\Client->__call('offsetGet', Array) error message suggests that there might be an unexpected dynamic method call or configuration issue within Guzzle.
    Log bellow:
GuzzleHttp\Exception\ServerException: Server error: `OFFSETGET https://endpoint-api/api/v1/router` resulted in a `501 Not Implemented` response:
OFFSETGET method is not supported
 in /var/app/current/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
....
#0 app/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 app/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 app/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 app/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 app/vendor/guzzlehttp/promises/src/Promise.php(246): GuzzleHttp\Promise\TaskQueue->run(true)
#5 app/vendor/guzzlehttp/promises/src/Promise.php(223): GuzzleHttp\Promise\Promise->invokeWaitFn()
#6 app/vendor/guzzlehttp/promises/src/Promise.php(267): GuzzleHttp\Promise\Promise->waitIfPending()
#7 app/vendor/guzzlehttp/promises/src/Promise.php(225): GuzzleHttp\Promise\Promise->invokeWaitList()
#8 app/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#9 app/vendor/guzzlehttp/guzzle/src/Client.php(131): GuzzleHttp\Promise\Promise->wait()
#10 app/vendor/guzzlehttp/guzzle/src/Client.php(89): GuzzleHttp\Client->request('offsetGet', 'router', Array)
#11 /app/src/Remote/RemoteClient.php(36): GuzzleHttp\Client->__call('offsetGet', Array)
#12 /app/src/Remote/Remote.php(186): App\Core\Remote\RemoteClient->sendRequest()
#13 /app/src/Remote/Remote.php(230): App\Core\Remote\Remote->sendRequest('GET', 'target/con...', Array)
#14 /app/src/Advice/Remote/TargetRemote.php(25): App\Core\Remote\Remote->get()

I have done some research on the internet and found a link related to the topic.
https://stackoverflow.com/questions/66710501/guzzlehttp-sending-weird-request-with-weird-http-method
The temporary solution is to reset the container, in accordance with the current situation. But it will continue in the future.

@mfn
Copy link

mfn commented Sep 14, 2023

The GuzzleHttp\Client->__call('offsetGet', Array) error message suggests that there might be an unexpected dynamic method call or configuration issue within Guzzle.

But the log further below shows this:

#10 app/vendor/guzzlehttp/guzzle/src/Client.php(89): GuzzleHttp\Client->request('offsetGet', 'router', Array)
#11 /app/src/Remote/RemoteClient.php(36): GuzzleHttp\Client->__call('offsetGet', Array)

This is your code calling this? What happens at and around like 36 of RemoteClient.php?

@mvn-trungtran-dn
Copy link
Author

mvn-trungtran-dn commented Sep 14, 2023

@mfn
thank for answer to me !

About your question

This is your code calling this? What happens at and around like 36 of RemoteClient.php?

RemoteClient.php is a block of code I provided in the description above.
line 36 is create new Client:

// RemoteClient.php
32 public function sendRequest()
33    {
34        $client = new Client([
35         'base_uri' => $this->request->getBaseUri(),
36         'headers' => $this->request->getHeaders(),
37    ]);
38     $options = array_merge($this->request->getParams(), ['timeout' => env('TIMEOUT'), 'connect_timeout' => env('CONNECT_TIMEOUT')]);
39      $response = $client->request(
40         $this->request->getMethod(),
41        $this->request->getUri(),
42        $options
43    );
    .....
    }

I see this line GuzzleHttp\Client->__call('offsetGet', Array) is call when create new Client(), but offsetGet is weird parameter, I don't think it send from my code
Feel free to ask me to provide more code or information . Thank you !

@mfn
Copy link

mfn commented Sep 14, 2023

Well, first thing coming to my mind is https://www.php.net/manual/en/arrayaccess.offsetget.php . Guzzle isn't using that so…

Copy link

stale bot commented Mar 17, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 2 weeks if no further activity occurs. Thank you for your contributions.

@stale stale bot added the lifecycle/stale No activity for a long time label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale No activity for a long time
Projects
None yet
Development

No branches or pull requests

2 participants