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

Closing old connection #430

Open
ptorrent opened this issue Feb 4, 2023 · 3 comments
Open

Closing old connection #430

ptorrent opened this issue Feb 4, 2023 · 3 comments
Labels
1.1 Issue related to Tinc 1.1 bug Issues in which the users gave a clear indication to the causes of the unexpected behaviour solution_exists A solution for the issue has already been suggested in the discussion.

Comments

@ptorrent
Copy link

ptorrent commented Feb 4, 2023

Hello,

I've 2 nodes in tinc version 1.1pre18

Both nodes listening on 65000

  1. start both deamon, everything works after ~5 seconds
  2. restart at the same time both deamon, here the output (~ same on both nodes) :
Ready


Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51624
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection

Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Why it closes the only connection ? It's the only one working. Then there is a loop for about ~40 sec :


Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51624) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51624)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51624)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51626
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51626) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51626)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51626)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51630
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51630) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51630)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51630)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51632
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51632) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51632)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51632)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51634
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51634) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51634)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51634)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51636
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51636) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51636)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51636)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51638
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51638) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51638)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51638)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51642
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51642) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51642)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51642)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51644
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)

Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51644) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51644)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51644)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51646
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51646) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51646)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51646)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51648
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51648) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51648)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51648)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51650
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51650) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51650)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51650)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51654
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51654) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51654)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51654)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51656
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51656) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51656)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51656)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51658
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51658) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51658)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51658)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51660
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51660) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51660)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51660)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51664
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51664) activated
Connection closed by b8_27_eb_23_73_87 (26.0.0.77 port 51664)
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51664)
Could not set up a meta connection to b8_27_eb_23_73_87

Trying to re-establish outgoing connection in 5 seconds
Trying to connect to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection from 26.0.0.77 port 51666
Connected to b8_27_eb_23_73_87 (26.0.0.77 port 65000)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 51666) activated
Established a second connection with b8_27_eb_23_73_87 (26.0.0.77 port 51666), closing old connection
Closing connection with b8_27_eb_23_73_87 (26.0.0.77 port 51666)
Connection with b8_27_eb_23_73_87 (26.0.0.77 port 65000) activated

NOW WORKING !

After a while ~ 1 minute. It's working weel.

Any idea why this strange behavior ?

@osdu
Copy link

osdu commented Feb 22, 2023

300-Skip-Autodisconnecting-for-ConnectTo-node.patch

--- a/src/autoconnect.c
+++ b/src/autoconnect.c
@@ -114,7 +114,7 @@ static void drop_superfluous_outgoing_co
 	int count = 0;
 
 	for list_each(connection_t, c, connection_list) {
-		if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree->count < 2) {
+		if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree->count < 2 || c->node->is_connect_to) {
 			continue;
 		}
 
@@ -128,7 +128,7 @@ static void drop_superfluous_outgoing_co
 	int r = rand() % count;
 
 	for list_each(connection_t, c, connection_list) {
-		if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree->count < 2) {
+		if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree->count < 2 || c->node->is_connect_to) {
 			continue;
 		}
 
@@ -156,11 +156,11 @@ static void drop_superfluous_pending_con
 			}
 		}
 
-		if(found) {
+		if(found || o->node->is_connect_to) {
 			continue;
 		}
 
-		logger(DEBUG_CONNECTIONS, LOG_INFO, "Cancelled outgoing connection to %s", o->node->name);
+		logger(DEBUG_CONNECTIONS, LOG_INFO, "Cancelled outgoing connection to %s:%d", o->node->name, o->node->is_connect_to ? 1 : 0);
 		list_delete_node(outgoing_list, node);
 	}
 }
@@ -182,7 +182,7 @@ void do_autoconnect() {
 	}
 
 	/* More than 3 connections? See if we can get rid of a superfluous one. */
-	if(nc > 3) {
+	if(nc > 5) {
 		drop_superfluous_outgoing_connection();
 	}
 
--- a/src/net_setup.c
+++ b/src/net_setup.c
@@ -411,6 +411,7 @@ void load_all_nodes(void) {
 
 		if(lookup_config(config_tree, "Address")) {
 			n->status.has_address = true;
+			n->is_connect_to = true;
 		}
 
 		exit_configuration(&config_tree);
--- a/src/net_socket.c
+++ b/src/net_socket.c
@@ -871,6 +871,7 @@ void try_outgoing_connections(void) {
 			if(!n) {
 				n = new_node();
 				n->name = xstrdup(name);
+				n->is_connect_to = true;
 				node_add(n);
 			}
 
--- a/src/node.c
+++ b/src/node.c
@@ -81,6 +81,7 @@ node_t *new_node(void) {
 	n->mtu = MTU;
 	n->maxmtu = MTU;
 	n->udp_ping_rtt = -1;
+	n->is_connect_to = false;
 
 	return n;
 }
--- a/src/node.h
+++ b/src/node.h
@@ -50,6 +50,7 @@ typedef struct node_t {
 	char *hostname;                         /* the hostname of its real ip */
 	node_id_t id;                           /* unique node ID (name hash) */
 	uint32_t options;                       /* options turned on for this node */
+	bool is_connect_to;                     /* true if is connectTo node */
 
 	int sock;                               /* Socket to use for outgoing UDP packets */
 	sockaddr_t address;                     /* his real (internet) ip to send UDP packets to */

@ptorrent
Copy link
Author

Thanks !

@gsliepen
Copy link
Owner

When two nodes connect to each other at exactly the same time, one node should drop its connection. A deterministic tie breaker should be implemented here.

@gsliepen gsliepen added bug Issues in which the users gave a clear indication to the causes of the unexpected behaviour solution_exists A solution for the issue has already been suggested in the discussion. 1.1 Issue related to Tinc 1.1 labels Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.1 Issue related to Tinc 1.1 bug Issues in which the users gave a clear indication to the causes of the unexpected behaviour solution_exists A solution for the issue has already been suggested in the discussion.
Projects
None yet
Development

No branches or pull requests

3 participants