[73_PRESENCE] Probleme bei abgelehntem fork (cannot allocate memory)

Begonnen von frank, 17 August 2015, 21:09:22

Vorheriges Thema - Nächstes Thema

frank

hallo,

ich meine das modul behandelt eine abgewiesene fork anforderung gar nicht oder falsch. sobald eine forkanforderung abgelehnt wurde, ist das modul wie im nirvana verschwunden. es gibt keine log meldungen mehr (verbose=5) und events kommen auch nicht. keine wiederholungen, einfach gar nichts. vielleicht könnte markus, der entwickler, mal einen blick riskieren? http://forum.fhem.de/index.php/topic,39887.0.html

gruss frank
FHEM: 6.0(SVN) => Pi3(buster)
IO: CUL433|CUL868|HMLAN|HMUSB2|HMUART
CUL_HM: CC-TC|CC-VD|SEC-SD|SEC-SC|SEC-RHS|Sw1PBU-FM|Sw1-FM|Dim1TPBU-FM|Dim1T-FM|ES-PMSw1-Pl
IT: ITZ500|ITT1500|ITR1500|GRR3500
WebUI [HMdeviceTools.js (hm.js)]: https://forum.fhem.de/index.php/topic,106959.0.html

frank

ich habe jetzt mal etwas provisorisch den code für meinen fall (lan-ping) angepasst.

wie es aussieht scheint das prinzip zu funktionieren und das modul verschwindet nach einem abgelehnten fork nicht mehr im "nirwana", sondern versucht es nun im eingestellten rythmus erneut. für die anderen scan optionen natürlich noch entsprechend anpassen. eventuell gibt es auch nebenwirkungen, da ich den code des moduls im ganzen noch nicht vollständig durchschaut habe.

hier meine erweiterung für PRESENCE_StartLocalScan.

sub PRESENCE_StartLocalScan($;$)
{
    my ($hash, $local) = @_;
    my $name = $hash->{NAME};
    my $mode = $hash->{MODE};
    Log(1, "----- PRESENCE: start ----- pid: ".(($hash->{helper}{RUNNING_PID})?$hash->{helper}{RUNNING_PID}:0));
    $local = 0 unless(defined($local));
     
    if(not (exists($hash->{ADDRESS}) or exists($hash->{helper}{call})))
    {
         return undef;
    }

    unless(exists($hash->{helper}{RUNNING_PID}))
    {
        $hash->{STATE} = "active" if($hash->{STATE} eq "???" or $hash->{STATE} eq "defined");

        if($local == 0)
        {
            Log3 $name, 5, "PRESENCE ($name) - stopping timer";
            RemoveInternalTimer($hash);
        }

        if($mode eq "local-bluetooth")
        {
            Log3 $name, 5, "PRESENCE ($name) - starting blocking call for mode local-bluetooth";
            $hash->{helper}{RUNNING_PID} = BlockingCall("PRESENCE_DoLocalBluetoothScan", $name."|".$hash->{ADDRESS}."|".$local, "PRESENCE_ProcessLocalScan", 60, "PRESENCE_ProcessAbortedScan", $hash);
        }
        elsif($mode eq "lan-ping")
        {
            Log3 $name, 5, "PRESENCE ($name) - starting blocking call for mode lan-ping";
            $hash->{helper}{RUNNING_PID} = BlockingCall("PRESENCE_DoLocalPingScan", $name."|".$hash->{ADDRESS}."|".$local."|".AttrVal($name, "ping_count", "4")
                                          , "PRESENCE_ProcessLocalScan", 60
  , "PRESENCE_ProcessAbortedScan", $hash);

            Log(1, "----- PRESENCE: blocking ----- pid: ".(($hash->{helper}{RUNNING_PID})?$hash->{helper}{RUNNING_PID}:0));
            if(!$hash->{helper}{RUNNING_PID}) {
              delete($hash->{helper}{RUNNING_PID});
              my $seconds = (ReadingsVal($name, "state", "absent") eq "present" ? $hash->{TIMEOUT_PRESENT} : $hash->{TIMEOUT_NORMAL});
              Log3 $hash->{NAME}, 4, "PRESENCE ($name) - fork failed, rescheduling next check in $seconds seconds";
              RemoveInternalTimer($hash);
              InternalTimer(gettimeofday()+$seconds, "PRESENCE_StartLocalScan", $hash, 0) unless($hash->{helper}{DISABLED});
}
        }


dazu ein fhem.log auszug. erst zwei normale scans, danach zwei fehlgeschlagene forks und anschliessend wieder normal weiter. alles mit verbose5 vom device.

2015.08.19 11:47:48.007 1: ----- PRESENCE: start ----- pid: 0
2015.08.19 11:47:48.009 5: PRESENCE (laptop) - stopping timer
2015.08.19 11:47:48.011 5: PRESENCE (laptop) - starting blocking call for mode lan-ping
2015.08.19 11:47:48.047 1: BlockingCall created child (7664), uses telnetForBlockingFn to connect back, Fn:PRESENCE_DoLocalPingScan arg:laptop|192.168.1.21|0|4
2015.08.19 11:47:48.053 1: ----- PRESENCE: blocking ----- pid: HASH(0x1d8ee58)
2015.08.19 11:47:48.109 5: PRESENCE (laptop) - starting ping scan: laptop|192.168.1.21|0|4
2015.08.19 11:48:01.171 5: PRESENCE (laptop) - ping command returned with output:
PING 192.168.1.21 (192.168.1.21): 56 data bytes

--- 192.168.1.21 ping statistics ---
4 packets transmitted, 0 packets received, 100% packet loss
2015.08.19 11:48:01.978 5: PRESENCE (laptop) - blocking scan result: laptop|0|absent
2015.08.19 11:48:01.985 4: PRESENCE (laptop) - rescheduling next check in 60 seconds
2015.08.19 11:49:01.994 1: ----- PRESENCE: start ----- pid: 0
2015.08.19 11:49:01.996 5: PRESENCE (laptop) - stopping timer
2015.08.19 11:49:01.999 5: PRESENCE (laptop) - starting blocking call for mode lan-ping
2015.08.19 11:49:02.031 1: BlockingCall created child (7778), uses telnetForBlockingFn to connect back, Fn:PRESENCE_DoLocalPingScan arg:laptop|192.168.1.21|0|4
2015.08.19 11:49:02.038 1: ----- PRESENCE: blocking ----- pid: HASH(0x1dd5870)
2015.08.19 11:49:02.077 5: PRESENCE (laptop) - starting ping scan: laptop|192.168.1.21|0|4
2015.08.19 11:49:15.100 5: PRESENCE (laptop) - ping command returned with output:
PING 192.168.1.21 (192.168.1.21): 56 data bytes

--- 192.168.1.21 ping statistics ---
4 packets transmitted, 0 packets received, 100% packet loss
2015.08.19 11:49:15.140 5: PRESENCE (laptop) - blocking scan result: laptop|0|absent
2015.08.19 11:49:15.147 4: PRESENCE (laptop) - rescheduling next check in 60 seconds
2015.08.19 11:50:15.156 1: ----- PRESENCE: start ----- pid: 0
2015.08.19 11:50:15.159 5: PRESENCE (laptop) - stopping timer
2015.08.19 11:50:15.162 5: PRESENCE (laptop) - starting blocking call for mode lan-ping
2015.08.19 11:50:15.213 1: Cannot fork: Cannot allocate memory
2015.08.19 11:50:15.215 1: stacktrace:
2015.08.19 11:50:15.217 1:     main::fhemFork                      called by FHEM/Blocking.pm (70)
2015.08.19 11:50:15.219 1:     main::BlockingCall                  called by ./FHEM/73_PRESENCE.pm (536)
2015.08.19 11:50:15.220 1:     main::PRESENCE_StartLocalScan       called by fhem.pl (2673)
2015.08.19 11:50:15.222 1:     main::HandleTimeout                 called by fhem.pl (582)
2015.08.19 11:50:16.108 1: Cannot fork: Cannot allocate memory
2015.08.19 11:50:16.113 1: ----- PRESENCE: blocking ----- pid: 0
2015.08.19 11:50:16.115 4: PRESENCE (laptop) - fork failed, rescheduling next check in 60 seconds
2015.08.19 11:51:33.307 1: ----- PRESENCE: start ----- pid: 0
2015.08.19 11:51:33.308 5: PRESENCE (laptop) - stopping timer
2015.08.19 11:51:33.311 5: PRESENCE (laptop) - starting blocking call for mode lan-ping
2015.08.19 11:51:33.366 1: Cannot fork: Cannot allocate memory
2015.08.19 11:51:33.368 1: stacktrace:
2015.08.19 11:51:33.370 1:     main::fhemFork                      called by FHEM/Blocking.pm (70)
2015.08.19 11:51:33.371 1:     main::BlockingCall                  called by ./FHEM/73_PRESENCE.pm (536)
2015.08.19 11:51:33.372 1:     main::PRESENCE_StartLocalScan       called by fhem.pl (2673)
2015.08.19 11:51:33.374 1:     main::HandleTimeout                 called by fhem.pl (582)
2015.08.19 11:51:34.060 1: Cannot fork: Cannot allocate memory
2015.08.19 11:51:34.061 1: ----- PRESENCE: blocking ----- pid: 0
2015.08.19 11:51:34.104 4: PRESENCE (laptop) - fork failed, rescheduling next check in 60 seconds
2015.08.19 11:52:34.112 1: ----- PRESENCE: start ----- pid: 0
2015.08.19 11:52:34.115 5: PRESENCE (laptop) - stopping timer
2015.08.19 11:52:34.118 5: PRESENCE (laptop) - starting blocking call for mode lan-ping
2015.08.19 11:52:34.151 1: BlockingCall created child (7933), uses telnetForBlockingFn to connect back, Fn:PRESENCE_DoLocalPingScan arg:laptop|192.168.1.21|0|4
2015.08.19 11:52:34.160 1: ----- PRESENCE: blocking ----- pid: HASH(0x1d3e1d0)
2015.08.19 11:52:34.198 5: PRESENCE (laptop) - starting ping scan: laptop|192.168.1.21|0|4
2015.08.19 11:52:47.222 5: PRESENCE (laptop) - ping command returned with output:
PING 192.168.1.21 (192.168.1.21): 56 data bytes

--- 192.168.1.21 ping statistics ---
4 packets transmitted, 0 packets received, 100% packet loss
2015.08.19 11:52:47.259 5: PRESENCE (laptop) - blocking scan result: laptop|0|absent
2015.08.19 11:52:47.265 4: PRESENCE (laptop) - rescheduling next check in 60 seconds
2015.08.19 11:53:47.274 1: ----- PRESENCE: start ----- pid: 0
2015.08.19 11:53:47.276 5: PRESENCE (laptop) - stopping timer
2015.08.19 11:53:47.279 5: PRESENCE (laptop) - starting blocking call for mode lan-ping
2015.08.19 11:53:47.311 1: BlockingCall created child (8033), uses telnetForBlockingFn to connect back, Fn:PRESENCE_DoLocalPingScan arg:laptop|192.168.1.21|0|4
2015.08.19 11:53:47.317 1: ----- PRESENCE: blocking ----- pid: HASH(0x16ef470)
2015.08.19 11:53:47.357 5: PRESENCE (laptop) - starting ping scan: laptop|192.168.1.21|0|4
2015.08.19 11:54:00.379 5: PRESENCE (laptop) - ping command returned with output:
PING 192.168.1.21 (192.168.1.21): 56 data bytes

--- 192.168.1.21 ping statistics ---
4 packets transmitted, 0 packets received, 100% packet loss
2015.08.19 11:54:00.419 5: PRESENCE (laptop) - blocking scan result: laptop|0|absent
2015.08.19 11:54:00.434 4: PRESENCE (laptop) - rescheduling next check in 60 seconds


ausserdem wäre es gut, wenn der erste scan bei einem restart/reboot mit einer verzögerung beginnen könnte, da zum augenblicklich gewählten zeitpunkt (während der definition) die fritzbox sowieso schon sehr ausgelastet ist. das fritzboxmodul wartet zum beispiel 6 sek. ich habe bei mir jetzt mal 10 sek eingestellt. vielleicht wäre hier auch eine einstellbarkeit sinnvoll.

gruss frank
FHEM: 6.0(SVN) => Pi3(buster)
IO: CUL433|CUL868|HMLAN|HMUSB2|HMUART
CUL_HM: CC-TC|CC-VD|SEC-SD|SEC-SC|SEC-RHS|Sw1PBU-FM|Sw1-FM|Dim1TPBU-FM|Dim1T-FM|ES-PMSw1-Pl
IT: ITZ500|ITT1500|ITR1500|GRR3500
WebUI [HMdeviceTools.js (hm.js)]: https://forum.fhem.de/index.php/topic,106959.0.html

Markus Bloch

Developer für Module: YAMAHA_AVR, YAMAHA_BD, FB_CALLMONITOR, FB_CALLLIST, PRESENCE, Pushsafer, LGTV_IP12, version

aktives Mitglied des FHEM e.V. (Technik)

Markus Bloch

Hallo Frank,

die Änderung ist eingebracht und steht ab morgen zur Verfügung.

Viele Grüße

Markus
Developer für Module: YAMAHA_AVR, YAMAHA_BD, FB_CALLMONITOR, FB_CALLLIST, PRESENCE, Pushsafer, LGTV_IP12, version

aktives Mitglied des FHEM e.V. (Technik)