From: Dirk Koopman Date: Sat, 23 May 2020 13:51:09 +0000 (+0100) Subject: try to fix DXSubprocess errors X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=bfd4e140dcf03f12bbda1dd405f8b135f86d0b6a;p=spider.git try to fix DXSubprocess errors That are happening at the EA3CV-2. Also make sure that an incoming connection's IP address is recorded. --- diff --git a/perl/DXSubprocess.pm b/perl/DXSubprocess.pm index 44427621..6ff5adae 100644 --- a/perl/DXSubprocess.pm +++ b/perl/DXSubprocess.pm @@ -8,6 +8,7 @@ package DXSubprocess; use DXUtil; use DXDebug; +use DXLog; use Mojo::IOLoop; use Mojo::IOLoop::Subprocess; use JSON; @@ -18,6 +19,45 @@ sub new { my $pkg = shift; my $class = ref $pkg || __PACKAGE__; - my $ref = Mojo::IOLoop::Subprocess->new->serialize(\&encode_json)->deserialize(\&decode_json); + my $ref = Mojo::IOLoop::Subprocess->new->serialize(\&freeze)->deserialize(\&thaw); return bless $ref, $class; } + +sub freeze +{ + my $r; + my $j = shift; + unless ($j) { + LogDbg('DXUser', "DXSubcommand::freeze: undefined or empty input"); + return q{[null, ""]}; + } + + eval { $r = encode_json($j) }; + if ($@) { + my $dd = dd($j); + LogDbg('DXUser', "DXSubcommand::freeze: json error on '$dd': $@"); + $r = qq{['$@','']}; + } + return $r; +} + +sub thaw +{ + my $r; + my $j = shift; + unless ($j) { + LogDbg('DXUser', "DXSubcommand::thaw: empty string on input"); + return q{[null, ""]}; + } + + return [undef, [1]] unless $j; + eval { $r = decode_json($j) }; + if ($@) { + LogDbg('DXUser', "DXSubcommand::thaw: json error on '$j': $@"); + $r = qq{[$@,[1]]}; + } + return $r; +} +1; + + diff --git a/perl/DXUser.pm b/perl/DXUser.pm index 79f8eff9..fb88ad82 100644 --- a/perl/DXUser.pm +++ b/perl/DXUser.pm @@ -196,13 +196,13 @@ sub init if (-e $filename || -e "$filename.n" || -e "$filename.o") { $v4 = 1; } else { - if (-e localdata('users.v3')) { - LogDbg('DXUser', "Converting " . localdata('users.v3') . " to new json version of users file, please wait"); - if (-x $convert) { - system($convert); - ++$export; - } - } +# if (-e localdata('users.v3')) { +# LogDbg('DXUser', "Converting " . localdata('users.v3') . " to new json version of users file, please wait"); +# if (-x $convert) { +# system($convert); +# ++$export; +# } +# } die "User file $filename missing, please run $convert or copy a user_json backup from somewhere\n" unless -e "$filename.n" || -s $filename; } diff --git a/perl/Msg.pm b/perl/Msg.pm index 3c4b51f3..5e40d3c2 100644 --- a/perl/Msg.pm +++ b/perl/Msg.pm @@ -146,7 +146,7 @@ sub _on_connect $sock->timeout(0); $sock->start; $conn->{peerhost} = eval { $handle->peerhost; }; - dbg((ref $conn) . " connected $conn->{cnum} to $conn->{peerhost}:$conn->{peerport}") if isdbg('connll'); + dbg((ref $conn) . " connected $conn->{cnum} to $conn->{peerhost}:$conn->{peerport}") if isdbg('conn') || isdbg ('connect'); if ($conn->{on_connect}) { &{$conn->{on_connect}}($conn, $handle); } @@ -485,7 +485,7 @@ sub new_client { $conn->{peerhost} = $handle->peerhost; $conn->{peerhost} =~ s|^::ffff:||; # chop off leading pseudo IPV6 stuff on dual stack listeners $conn->{peerport} = $handle->peerport; - dbg((ref $conn) . " accept $conn->{cnum} from $conn->{peerhost}:$conn->{peerport}") if isdbg('connll'); + dbg((ref $conn) . " accept $conn->{cnum} from $conn->{peerhost}:$conn->{peerport}") if isdbg('conn') || isdbg('connect'); my ($rproc, $eproc) = &{$server_conn->{rproc}} ($conn, $conn->{peerhost}, $conn->{peerport}); $conn->{sort} = 'Incoming'; if ($eproc) {