parse-community / parse-php-sdk

The PHP SDK for Parse Platform
https://parseplatform.org/
Other
811 stars 346 forks source link

ParsePlatform PHP ParseException unauthorized #396

Closed tigpt closed 6 years ago

tigpt commented 6 years ago

Issue Description

I have parse-server:2.7.4 running in docker with database on mlab.com and php:5.6.30 and everything was fine until last days, I started notice some problems and when debugging I found that sometimes (more or less half of the times it work as expected, the other half it just gives me the exception bellow) my ParseQuerys work fine, other they throw a ParseException as below.

Don't know what else I can do to investigate the cause of this problem. anyone with some tips on how to debug this?

If I do $health = ParseClient::getServerHealth(); it always work as normal, but with a simple query as in the log it works 1/2 of the times.

Thanks a lot.

Environment Details

Logs/Traces

at parse server, if I set verbose, it works as normal when the result in php is correct, don't show any error when doesn't, like if the parse-server was not hit at all. As the PHP I have this output when var_dump the error in a try catch.

    object(Parse\ParseException)#6 (7) {
      ["message":protected]=>
      string(12) "unauthorized"
      ["string":"Exception":private]=>
      string(0) ""
      ["code":protected]=>
      int(0)
      ["file":protected]=>
      string(85) "(...)/vendor/parse/php-sdk/src/Parse/ParseClient.php"
      ["line":protected]=>
      int(604)
      ["trace":"Exception":private]=>
      array(3) {
        [0]=>
        array(6) {
          ["file"]=>
          string(84) "(...)/vendor/parse/php-sdk/src/Parse/ParseQuery.php"
          ["line"]=>
          int(601)
          ["function"]=>
          string(8) "_request"
          ["class"]=>
          string(17) "Parse\ParseClient"
          ["type"]=>
          string(2) "::"
          ["args"]=>
          array(5) {
            [0]=>
            string(3) "GET"
            [1]=>
            string(32) "classes/Draw?limit=1&order=-date"
            [2]=>
            NULL
            [3]=>
            NULL
            [4]=>
            bool(false)
          }
        }
        [1]=>
        array(6) {
          ["file"]=>
          string(84) "(...)/vendor/parse/php-sdk/src/Parse/ParseQuery.php"
          ["line"]=>
          int(470)
          ["function"]=>
          string(4) "find"
          ["class"]=>
          string(16) "Parse\ParseQuery"
          ["type"]=>
          string(2) "->"
          ["args"]=>
          array(1) {
            [0]=>
            bool(false)
          }
        }
        [2]=>
        array(6) {
          ["file"]=>
          string(57) "(...)/my_php_file.php"
          ["line"]=>
          int(25)
          ["function"]=>
          string(5) "first"
          ["class"]=>
          string(16) "Parse\ParseQuery"
          ["type"]=>
          string(2) "->"
          ["args"]=>
          array(0) {
          }
        }
      }
      ["previous":"Exception":private]=>
      NULL
    }
tigpt commented 6 years ago

This happens exactly request yes, request no, and its predictable, if it failed now, it works the next request and so on.

I try installing php:7.2 and its the same, the error occurred between php and parse-server since on parse-server logs the request don't apear.

I try with composer installing parse php-sdk 1.3.0, and even 1.2.9 and it stays the same as with 1.4.0

I don't know where else to debug this.

I'm using Cloudflare, I tried purge cache and even activate development mode, that put Cloudflare as dns server only.

Can anyone tell me how can I debug whats happening between php and parse-server, something here is making my requests to fail.

I even tried to change the parse-server configs from https://domain.name to local server http://parse-server-docker-name:1337 and it is exactly equal.

The error says its on line 600 of /vendor/parse/php-sdk/src/Parse/ParseQuery.php

public function find($useMasterKey = false)
    {
        $sessionToken = null;
        if (ParseUser::getCurrentUser()) {
            $sessionToken = ParseUser::getCurrentUser()->getSessionToken();
        }
        $queryString = $this->buildQueryString($this->_getOptions());
        $result = ParseClient::_request(
            'GET',
            'classes/'.$this->className.'?'.$queryString,
            $sessionToken,
            null,
            $useMasterKey
        );
        $output = [];
        foreach ($result['results'] as $row) {
            $obj = ParseObject::create($this->className, $row['objectId']);
            $obj->_mergeAfterFetchWithSelectedKeys($row, $this->selectedKeys);
            $output[] = $obj;
        }

        return $output;
    }

Line 600 is

$result = ParseClient::_request(
            'GET',
            'classes/'.$this->className.'?'.$queryString,
            $sessionToken,
            null,
            $useMasterKey
        );

Help me debugging this please.

tigpt commented 6 years ago

You can close this issue.

It was some problem related with my nginx proxy, I don't know why or how but it maybe thought there are 2 docker services replying to that domain, so it possibly load balance them.

I made a new cname with new docker service running parse server and it works fine with the new services. And stoping and launching old cname services or even nginx proxy, it stays with same behavior.

Anyway it was not parse-php-sdk problem.