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
No suitable servers found #791
Comments
Hi! When you say "it's not happening all the time" — could you be more precise? Does it happen once out of a hundred times, or once out of every 3? Which version of PHP, and the MongoDB driver are you using? You can use |
If I connect server like the code I provided above (the line for $server ), it's more like 4 out of 5. Some version info:
When I enter "php -v" in my terminal, it says
However, I already copy the mongodb.so to the extension directory in php56 directory, and set the follow in php.ini: I am not sure why it still wants to find the original mongodb.so, because I already delete that. it says
|
Connection ErrorIf we break down the original connection error, we see that server selection fails with the following individual errors for each node in the connection string's seed list:
Connection timeout is indicative of a generic socket timeout; however, I don't think lowering TLS handshake failure is more interesting and originates from
I'm not familiar with the inner workings of Secure Transport, but I expect this may be another manifestation of the connection timeout experienced with the other two nodes, but occurring during the TLS handshake process. Best I can tell, the only problem here is a connection error between your application server and the Atlas server. As an aside, I've opened CDRIVER-2602 to request that libmongoc translate the codes on its own -- which should save us some time in the future. ObservationsI do have a few observations about your script. Since your connection URI includes Lastly, I find it a bit curious that you're using driver version 1.3.4 but libmongoc/libbson 1.9.3. The 1.3.4 driver bundles libmongoc 1.8.2. It's clear that you're using libmongoc and libbson as system libraries, but I wonder why you've not upgraded to driver version 1.4.2 in this case (which bundles libmongoc 1.9.3). That said, there should be no issues using a newer version of libmongoc/libbson with the older driver, since the shared libraries preserve ABI. Installation IssuesOther users have reported similar issues installing the driver with Homebrew (Homebrew/brew#4021). I believe this is related to https://github.com/Homebrew/homebrew-php being recently deprecated, so we may need to update the macOS and Homebrew install docs to promote PECL as the correct install mechanism. That said, there appear to be some challenges with the move to PECL (Homebrew/homebrew-core#26108), so we'll have to consider that as well before rewriting the install docs. |
I issued a problem on https://jira.mongodb.org/browse/MMSSUPPORT-19732 about not able to connect to mongoDB several weeks ago, and the above connection code was provided by an assignee. Also, I don't know why the driver version is not matched with libmongoc. I don't recall that I intentionally specify any version during installation. Just download php56-mongodb using Home-brew, and add a .so path in php.ini file, and all above message appear in phpinfo(). So what should I do now? How to upgrade the driver? |
Thanks for sharing. I've left a private comment on that issue to inform the support assignee of the mistake. Looking at that issue, it appears that the connection issues were the result Atlas' IP whitelist and/or macOS Secure Transport not having the necessary certs available, which required you to manually provide a CA file. If this issue is not resolved, it may be helpful to see log output for a basic script that connects to the server and issues a basic ping command (sufficient to initialize all connections). // See: http://php.net/manual/en/mongodb.configuration.php
ini_set('mongodb.debug', 'stderr');
require 'vendor/autoload.php';
$uri = 'mongodb://csci571:<password>@cluster0-shard-00-00-b2gpc.mongodb.net:27017,cluster0-shard-00-01-b2gpc.mongodb.net:27017,cluster0-shard-00-02-b2gpc.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin';
$driverOptions = ['ca_file' => '/usr/local/etc/openssl/cert.pem'];
$client = new MongoDB\Client($uri, [], $driverOptions);
$cursor = $client->test->command(['ping' => 1]);
var_dump($cursor->toArray()[0]); Since this logs to stderr, I'd suggest running this from the CLI environment. Just make sure that
Now that the PHP extension formulae have been removed from Homebrew, the suggested installation method is to use You should be able to follow the standard PECL install instructions. |
I have reinstall the mongodb using pecl What information do you need to solve the original problem about fail to connect to server? |
The first half of my previous comment (#791 (comment)) walks through steps to investigate a connection issue by running a basic script that connects and pings from the CLI with full debugging logged to stderr. |
I have run the code that you provided
|
Since I reinstall the mongodb, here is new version info:
|
I'm not sure how your extension version is 1.5.0-dev if you've installed the driver through PECL. The most recent stable release in PECL is 1.4.3. Aside from that, there appears to be no issue connecting the the cluster if you're able to issue a |
Not every time it will fail to connect, and I am not sure what's the frequency that it fails to connect. It seems like a random event to me. |
If the only error observed is a connection timeout or "TLS handshake failed: -9806" (likely also a connection error per analysis in #791 (comment)), I expect the root cause is outside of the driver's control. For instance, this could be caused by a poor network connection between the application server and Atlas. While the The only other diagnostic tool available within the driver is trace logs, which would record the flow of functions called throughout libmongoc leading up to the error. These can be enabled via the |
An issue recently popped up for libmongoc, which the PHP driver uses, that I believe may be related to this errors you're experiencing. In CDRIVER-2624, the client and server may fail when attempting TLS renegotiation on an existing connection. The issue appears to be related to a non-OpenSSL library being used by either the driver or server. At the moment, 3.6 servers on Atlas should all be using OpenSSL, so I expect this is related to the driver using Secure Channel on macOS. With regard to the PHP driver, this would approximately happen at intervals >= That said, I think you can easily verify whether you are hitting this bug by creating a CLI script based on this example in CDRIVER-2624: <?php
require 'vendor/autoload.php';
$server = 'mongodb://csci571:<password>@cluster0-shard-00-00-b2gpc.mongodb.net:27017,cluster0-shard-00-01-b2gpc.mongodb.net:27017,cluster0-shard-00-02-b2gpc.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin';
/* Per my earlier comment about which SSL context options actually apply to the
* driver, I've reduced this considerably. Note that weak_cert_validation, the
* canonical alias of the allow_self_signed SSL context option, defaults to true
* so I've omitted it here. */
$driverOptions = ['ca_file' => '/usr/local/etc/openssl/cert.pem'];
while (true) {
/* We could easily create one client outside of the loop, but I wanted to
* demonstrate that each client we construct will share the same persisted
* sockets since the constructor arguments are the same. By lowering the
* monitoring interval to 500ms from 60s, we should see the error sooner. */
$client = new MongoDB\Client($uri, ['heartbeatFrequencyMS' => 500], $driverOptions);
$client->test->student->findOne();
/* Provide some indication of how many successful queries are performed */
echo '.';
} Running this from the CLI environment will hopefully reproduce the error within the first second of execution. |
I've opened PHPC-1169 as a tracking ticket. Once we know whether the libmongoc fix will be backported or not, we can triage our ticket accordingly so that it can be scheduled for a 1.4.x patch release or (worst case) upcoming 1.5.0 release when we bump our libmongoc dependency. |
I had a similar issue recently and found the cause was stale DNS caches upstream caused by recent changes to A records. The client would try to translate the domain name in the connection string into IP addresses. Sometimes this would work and sometimes not, as some DNS caches had the correct IP address and others had not yet updated. If that's the issue, you can simply replace the domain names with IP addresses in the connection string. |
PHPC-1169 was resolved in driver version 1.5.0, so I am closing this out. |
Description
The message is:
It's not happening all the time, but I couldn't figure out what cause it. The code is
First time to use mongodb, I cannot find where the log is.
The text was updated successfully, but these errors were encountered: