Not possible to use server after db = server.use? - orientdb

I was doing a very basic test using node.js, latest orientjs and latest OrientDB:
open server (using port 2424)
assign db (server.use)
server.list()
If I do this, the promise at server.list() hangs and the server shows the error "Impossible to read a chunk of length...". But if I just don't assign the db, it works fine. Also, if I call db functions (like db.record.get) instead of server.list(), that works fine too.
Is it the case that you can't call a server function after calling server.use?
On a related point, is there a way to set a network timeout for orientjs? If I try to do any of this and the target server is not reachable, it just hangs on opening the server and/or assigning the database.

Related

Postgres, Prisma Working Fine One Day, 'P1001 Error: Can't Reach Database' the next

For this project, I am using a prisma / Postgres database. I have made no changes to my code, and I have pulled a coworkers working version of the code to no avail. I am unable to do anything with the database, I cannot migrate, I cannot run mutations, and I cannot even open the psql console, as every command is met with
P1001: Can't reach database server at localhost:5432
Please make sure your database server is running at localhost:5432
I am not sure what I could have possibly done, I don't know enough about ports or even the contents of app.json well enough to have messed anything up. Now, no mutations can go through.
Interestingly enough, this all happened after I ran npx primsa migrate deploy on the deployed database which is on a EC2 VM from AWS. Since then, the native app associated with the database refuses to work, though it is worth nothing that the webapp connects to the deployed database just fine. This being said, nothing works locally, as the database / Port / Server don't exist anymore according to my machine, which makes no sense. I have no idea how to try to re-spin it, or why every single query / mutation from my Native App now ONLy returns Response not successful: Received status code 400 despite it having the same exact syntax it did when it worked, as well as the WebApp having the same syntax and server (ExpressJS). Does anyone have any ideas what could be causing this?
The error code 400 refers to a bad request coming from the client: too large request, malformed syntax, invalid request message framing, etc.
First step: make sure that your database server is indeed running. Try connecting to it with other SQL Clients or Libraries. Sometimes Prisma is just being difficult.
Second thing: are you hosting the database on the local server? I can assume you are because of the localhost. Make sure no other programs are using this port or maybe waiting for it.
Sorry if this doesn't help. Good luck!

MongoDB Rust Client Connection Errors

I am a Rust newbie and am trying to create a REST API using actix and mongodb.
Before starting up the I am trying to connect to a local MongoDB instance Using the official rust client from here. Here is the code I am trying
let client = Client::with_uri_str("mongodb://localhost:27017").expect("Error getting client");
let database = client.database("mydb");
let collection = database.collection("books");
Rustc version is 1.44 and MongoDB driver version 1.0.0
While running this code, I do not get an error if the local mongodb server is not running.
How do we figure out if the connection to the DB has been successful or not ? No point continuing if the DB connection itself is not established.
The drivers are required to establish connections in the background. Instantiating a client is supposed to always succeed.
The purpose of this is to, for example, allow the application and the database to be started at the same time - when the database becomes available, the application will be able to use it.
To find out whether your database is operational, execute a command such as ping. Most applications will simply carry on with their normal queries/updates.

How to initialise a mongokitten server globally in a swift file other than the main.swift file?

I use mongodb to store all data of my mac application.So I use Mongokitten library as the interface between the db and my app. Inorder to connect to db initially and maintain the connection throughout the time when application is running I need to establish a one time connection to db. But I'm not able to initialise the server globally in the swift file.What i do is connect to the server each time a operation(insertion, updation, deletion, read) is performed.This causes the connection to the server to be lost once when these operations are executed over a limit and causes my application to hang. Can anyone please help me find a solution to make the server connection only once for throughout running of application?
I found the answer.Implicitly unwrap the server variable and assign value to server on checking server connection.
For reference follow the link :https://swiftmodules.com/planteam/mongokitten

Query on Ratchet Socket

I am using Ratchet Socket. I have established a new server connection and I want to stop server from running. In this scenario I have IP(Hostname) and port with me, So how can I stop that?
Is it possible to make a server connection that never ends?
When I make a server connection, first day the data output is perfect from DB, But on second day, the error is generated as "Connection is closed by foreign host". But still I can connect to that port.
Code
<?php
use Ratchet\Server\IoServer;
use MyApp\Chat;
use React\EventLoop\Factory;
use React\ZMQ\Context;
require dirname(__DIR__) . '/vendor/autoload.php';
require dirname(__DIR__) . '/src/MyApp/Chat.php';
$server = IoServer::factory(
new Chat(),
6666
);
$server->run();
?>
1.
I am using Ratchet Socket. I have established a new server connection
and I want to stop server from running. In this scenario I have
IP(Hostname) and port with me, So how can I stop that?
I assume that you currently run your Ratchet server by running it as a php script in a terminal window or screen.
eg: php push-server.php
Once you stop running the script your server will stop.
2.
Is it possible to make a server connection that never ends?
Yes, if your php script stops working from the terminal, you have to manually restart it. Its better to use a program like Supervisor (A Process Control System) which is recommended by Ratchet.
Check this link for more info http://supervisord.org/installing.html
The supervisord service will monitor your php script and will automatically restart it if it crashes which is suited for production environments.
3.
When I make a server connection, first day the data output is perfect
from DB, But on second day, the error is generated as "Connection is
closed by foreign host". But still I can connect to that port.
This is quite common and I've noticed it too. It usually happens when the server is heavily loaded or times out. Your JavaScript should check for this message and re-initiate a new connection if you see this message. You can also get it to try again after a random timer as well.
Edits
Also the __construct method for the Ratchet\Server\IoServer requires 3 prams, of which the 3rd one being optional. The first and second need to be objects of MessageComponentInterface and ServerInterface.
public function __construct(MessageComponentInterface $app, ServerInterface $socket, LoopInterface $loop = null) {
The way you instantiate the IoServer seems incorrect.

Testing connectionTimeout threshold using Mongo Java driver 3.0.0

Mongo m = new MongoClient(new ServerAddress(server , port), creds, MongoClientOptions.builder().connectTimeout(2000).socketTimeout(2000).serverSelectionTimeout(10000).socketKeepAlive(true).build());
I want to test connectionTimeOut to a standalone server. Every time I define the wrong port for a client or stop the server, it fails on the select server step and returns a serverSelectionTimeOut. How can I test the connectionTimeOut threshold in a development environment?
You need to make sure that you are connecting to an existing server (hostname and port), because the connection is setup after the server-selection process. If server selection fails it won't go to the connection-setup step.
If there is no Mongo server that is always available for testing, try deploying an embedded Mongo server on the fly on your local machine instead. You could write a unit test that automatically launches the embedded Mongo at the start of the test (as is demonstrated here).
Alternatively you could use MongoUnit for testing, but I have no experience with that myself.
Once you have a proper server you can force a connectionTimeout, by setting the timeout value to 1 millisecond. You can do that in code
MongoClientOptions.builder().connectTimeout(1)
or by adding a setting to your database-url
mongodb://localhost:27017/your_database?connectTimeoutMS=1