[X2Go-Dev] Bug#302: Possible solution to #302 ?
GZNG Tech
tech at gznianguan.com
Thu Jun 12 18:58:17 CEST 2014
Control: tag -1 patch
Hi,
Putting the attached file into your "extensions/post-suspend.d" folder
on the server...
may solve #302 issues...
On Ubuntu that would be an executable named "302_bug-fix" with the
following full path:
/usr/lib/x2go/extensions/post-suspend.d/302_bug-fix
(On other distros just simply locate your "post-suspend.d" folder and
put it there..
PS! Make sure its executable! (chmod 755).
Its may be good to clean up all old sessions before you
start a brand new and fresh session to test this fix.
We were able to reliably reproduce fault/non-fault conditions and after
applying this fix, we're seeing 100% success rates for session resume
with pyhoca....
The source of the issue seem to be that the NX port reappears on the
server within seconds of session suspension.... in a state where where
its not ready for new incoming connections... (quite frankly it should
not be available at all at this time, should it?) So either we're
reconnecting to this "faulty" port
or the fresh port fails to open due to the "old port" being in the
way.... Either way NX fails to resume...
The problem seem to be consistently occurring when rapidly
suspending/resuming with pyhoca and if x2goclient experience
abnormal/unclean disconnects that results in suspension.
Either way this little perl script will clean up those stray NX ports by
simply locating and connecting to them... (after which, the port closes,
as it should.)
If this indeed solves the #302 bug, this should probably move from
extensions to being part of the suspend scripts.... but for cleanliness
and admin-friendliness its easier to test it as an extension....
Let us know if this works for you!
(btw: If the supportive subs are adopted to Utils.pm the script it self
would become quite compact)
Best Regards,
-GZNGET
-------------- next part --------------
#!/usr/bin/perl
# We'd love to run this with -T but Utils.pm and probably DB.pm too need some work before that can happen..
########################################################################################################################
#
# Copyright (C) 2013-2014 X2Go Project - http://wiki.x2go.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Copyright (C) 2013-2014 Guangzhou Nianguan Electronics Technology Co.Ltd. <opensource at gznianguan.com>
#
#########################################################################################################################
#
# Hopefully this solves the issues pretaining to the #302 session resume bug.
# If so, we dedicate this bugfix to the Logitech D250 Keyboard who's servicelife came to an abrupt end due to this bug.
#
#########################################################################################################################
use strict;
use Sys::Hostname;
use IO::Socket;
use X2Go::Utils qw( sanitizer );
use X2Go::Server::DB qw(db_listsessions);
my $doRetryCnt = 5;
my $X2GoSID = requireX2GOSID_argvenvdie();
my @X2GoSesINFO = getSessionInfo($X2GoSID);
if (@X2GoSesINFO[1] eq $X2GoSID) {
while ($doRetryCnt > 0) {
$doRetryCnt--;
if (itsUP($X2GoSesINFO[8])) {
exit;
}
sleep 1;
}
}
########################################################################################################
# Only SUBS past this point....: (Any Utils.pm candidates?)
sub requireX2GOSID_argvenvdie { # Return X2Go SID from either ARGV[0]?or ENV.... terminates on failure.
# If this ends up moving to Utils.pm, renaming may be a good idea.
if (sanitizer("x2gosid", at ARGV[0])) {
return sanitizer("x2gosid", at ARGV[0]);
} elsif (sanitizer("x2gosid",$ENV{'X2GO_SESSION'})) {
return sanitizer("x2gosid",$ENV{'X2GO_SESSION'});
} else {
die "No X2Go Session ID in ARGV or ENV!\n";
}
}
sub itsUP { # Simple sub for checking if the port is up on localhost...
# If this ends up moving to Utils.pm, renaming may be a good idea.
my $portNum = sanitizer("num",$_[0]) or die "Port number not a number '$_[0]'?";
my $socket = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => $portNum, Proto => 'tcp');
if (defined $socket) {
print $socket "\n";
$socket->close;
return 1;
} else {
return 0;
}
}
sub getSessionInfo { # Simple sub to get X2GoSessionINFO from the database (kind of like greping it out of "x2golistsessions" without cranking another perl script)...
# If this ends up moving to Utils.pm, renaming may be a good idea.
my $theX2GoSID = $_[0];
foreach my $sessionLine (db_listsessions(hostname)) {
if ($sessionLine =~ /$theX2GoSID/) {
return split(/\|/,$sessionLine);
}
}
return 0;
}
More information about the x2go-dev
mailing list