Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Projets publics
Ravada-Mirror
Commits
b852bfbb
Commit
b852bfbb
authored
Jan 24, 2020
by
Francesc Guasch
Browse files
fix(backend): deal with conflicting ports
This problem raised when creating multiple clones and starting them all at once.
parent
96a41f54
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/Ravada/Domain.pm
View file @
b852bfbb
...
...
@@ -2365,31 +2365,46 @@ sub _add_expose($self, $internal_port, $name, $restricted) {
return
$public_port
;
}
sub
_open_exposed_port
($self, $internal_port, $name, $restricted) {
my
$sth
=
$$CONNECTOR
->
dbh
->
prepare
("
SELECT id,public_port FROM domain_ports
"
.
"
WHERE id_domain=? AND internal_port=?
"
);
$sth
->
execute
(
$self
->
id
,
$internal_port
);
my
(
$id_port
,
$public_port
)
=
$sth
->
fetchrow
();
if
(
!
$public_port
)
{
$public_port
=
$self
->
_vm
->
_new_free_port
();
sub
_set_public_port
($self, $id_port, $internal_port, $name, $restricted) {
my
$public_port
=
$self
->
_vm
->
_new_free_port
();
for
(;;)
{
if
(
$id_port
)
{
my
$sth
=
$$CONNECTOR
->
dbh
->
prepare
("
UPDATE domain_ports set public_port=?
"
.
"
WHERE id_domain=? AND internal_port=?
"
);
$sth
->
execute
(
$public_port
,
$self
->
id
,
$internal_port
);
eval
{
$sth
->
execute
(
$public_port
,
$self
->
id
,
$internal_port
);
};
die
$@
if
$@
&&
$@
!~
/uplicate entry/
;
return
$public_port
if
!
$@
;
}
else
{
my
$sth
=
$$CONNECTOR
->
dbh
->
prepare
("
INSERT INTO domain_ports
"
.
"
(id_domain, public_port, internal_port, name, restricted)
"
.
"
VALUES(?,?,?,?,?)
"
);
$sth
->
execute
(
$self
->
id
,
$public_port
,
$internal_port
,(
$name
or
undef
)
,
$restricted
.
"
(id_domain, public_port, internal_port, name, restricted)
"
.
"
VALUES(?,?,?,?,?)
"
);
eval
{
$sth
->
execute
(
$self
->
id
,
$public_port
,
$internal_port
,(
$name
or
undef
)
,
$restricted
);
};
die
$@
if
$@
&&
$@
!~
/uplicate entry/
;
return
$public_port
if
!
$@
;
}
$public_port
+=
int
(
rand
(
10
))
+
1
;
}
}
sub
_open_exposed_port
($self, $internal_port, $name, $restricted) {
my
$sth
=
$$CONNECTOR
->
dbh
->
prepare
("
SELECT id,public_port FROM domain_ports
"
.
"
WHERE id_domain=? AND internal_port=?
"
);
$sth
->
execute
(
$self
->
id
,
$internal_port
);
my
(
$id_port
,
$public_port
)
=
$sth
->
fetchrow
();
$public_port
=
$self
->
_set_public_port
(
$id_port
,
$internal_port
,
$name
,
$restricted
)
if
!
$public_port
;
my
$local_ip
=
$self
->
_vm
->
ip
;
my
$internal_ip
=
$self
->
ip
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment