2

I want to connect to the tarantool cotainer using this code:

import TarantoolConnection from 'tarantool-driver'
let connection = new TarantoolConnection('192.168.99.100:3301');
connection.ping().then((res) => {
   console.log(res);
});

Before that i started container:

docker run -p 3301:3301 -d tarantool/tarantool:1.6

But in result i get nothing.

If i try to create space or\and index for this space:

connection.eval("box.schema.space.create('myspace', {if_not_exists=true, temporary=true})").then((res) => {
    console.log(res);
});

I get this error:

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: This socket is closed

or:

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: connection will be destroyed or already destroyed, create another one

As i see from the error, the needed socket is already closed, but i don't understand why.

Version of tarantool driver:

"tarantool-driver": "2.0.5",

How can i fix it?

Nikita Ryanov
  • 1,520
  • 3
  • 17
  • 34

1 Answers1

2

You have two problems here:

  1. You should connect to localhost:3301 instead of 192.168.99.100:3301
  2. You have to use connection.connect() before connection.ping() or connection.eval()

Here is the working code:

const TarantoolConnection = require('tarantool-driver');

let connection = new TarantoolConnection({port: 3301});

connection.connect().then((res) => {
    console.log("Connected: " + res);

    connection.ping().then((res) => {
        console.log("Pong: " + res);
    });

    connection.eval("box.schema.space.create('myspace', {if_not_exists=true, temporary=true})").then((res) => {
        console.log("Space created");
    });
});

Just in case, I've used the following command to start tarantool docker instance:

$ docker run --rm -p 3301:3301 -t -i tarantool/tarantool:1.6
Vladimir Lebedev
  • 1,207
  • 1
  • 11
  • 25
  • Unfortunately, i still have the same error: UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: connect ECONNREFUSED 127.0.0.1:3301. Other containers work fine and i can connect to them – Nikita Ryanov Dec 08 '17 at 17:51
  • That's rather strange. Looks like that the tarantool driver can't connect to the tarantool docker container. With running tarantool container, could you please try to connect to it in the other shell window using `telnet localhost 3301` and tell me the result? – Vladimir Lebedev Dec 08 '17 at 18:53
  • That's really strange, because i can't even connect using telnet. I get the error: could not open connection to the host, using port 3301: connection error – Nikita Ryanov Dec 08 '17 at 21:56
  • But when i tried to connect uisng docker ip 192.168.99.100 it connected successfully (it it can be called so, because i get message like `Tarantool 1.6.9 (Binary) and strange sequence of symbols`) – Nikita Ryanov Dec 08 '17 at 22:02
  • 1
    Well, the message above is OK, it shows that you can connect to tarantool. Change in the third line of my code above `{port: 3301}` to `{host: '192.168.99.100', port: 3301}` and run it. It should work. The other question why port mapping to localhost doesn't work. Maybe there is something wrong with your docker setup. Could you please explain your OS and docker configuration? – Vladimir Lebedev Dec 09 '17 at 06:43
  • Thank you! Finally, it worked. Btw, i use Windows 7 and docker toolbox, what may be the reason why i can't use localhost – Nikita Ryanov Dec 09 '17 at 08:11
  • thank you very much, your answer is much more clear than the actual readme on github – ThomasP1988 May 25 '18 at 19:12