<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt; color: #000000"><div>Hi Sebastian,</div><div><br></div><div> Thanks for a prompt response. And yes, I was not very generous concerning details, so here's a hopefully better description:</div><div><br data-mce-bogus="1"></div><div>I have an expert bot of my own that I start normally and then reload it with intelmqctl reload. When I now push an event to it for processing, a message appears in the log saying </div><div><br data-mce-bogus="1"></div><div>"TypeError: 'NoneType' object is not subscriptable"</div><div><br data-mce-bogus="1"></div><div> This is due to a variable (dict) becoming undefined in the reload. During a normal start this variable gets however, properly initiated once the first event comes in for</div><div>processing. The reason for its initiation in the process method arises from the need to regularly update it from a file that changes occasionally. In other words, my bot's init method sets this variable</div><div> to None and if it is None when reaching the bot's process method, it gets initialised there before any accesses to it.<span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: 13.3333px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;" data-mce-style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: 13.3333px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"><span> </span>Later accesses/updates to this variable are successful unless I reload the bot.</span></div><div><br></div><div> In a reload, my bot's log starts with:</div><div><br data-mce-bogus="1"></div><div><div><span style="font-size: 13.3333px;">INFO - Received SIGHUP, initializin</span><span style="font-size: 13.3333px;">g again later.</span></div><div><span style="font-size: 13.3333px;">INFO - Handling SIGHUP, initializing again now.</span></div><div><span style="font-size: 13.3333px;"><br data-mce-bogus="1"></span></div><div><span style="font-size: 13.3333px;"> which leads me to assume that any possible delay needed ahead of a safe reload has passed and the reload can in fact take place as you describe below. There are indications that the Bot::__init__ (from intelmq/lib/bot.py) is run as</span></div><div><span style="font-size: 13.3333px;">the lines:</span></div><div><span style="font-size: 13.3333px;"><br data-mce-bogus="1"></span></div><div><span style="font-size: 13.3333px;">INFO - Bot is starting.</span><br data-mce-bogus="1"></div><div><span style="font-size: 13.3333px;">INFO - Bot initialization completed.</span><br data-mce-bogus="1"></div><div><span style="font-size: 13.3333px;"><br data-mce-bogus="1"></span></div><div><span style="font-size: 13.3333px;"> also show up in the bot's log. No log message from my bot's own init method gets written in between the above two, which leads me to assume that my bot's init method is not run, right? But shouldn't it be?</span></div><div><span style="font-size: 13.3333px;"><br data-mce-bogus="1"></span></div><div><span style="font-size: 13.3333px;">Thanks again, Mika</span></div></div><div><br data-mce-bogus="1"></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><b>From: </b>"Sebix" <sebix@sebix.at><br><b>To: </b>"Mika Silander" <mika.silander@csc.fi>, "intelmq-dev" <intelmq-dev@lists.cert.at><br><b>Sent: </b>Wednesday, 22 June, 2022 15:15:20<br><b>Subject: </b>Re: [IntelMQ-dev] Expected behaviour of intelmqctl reload ?<br></div><div><br></div><div data-marker="__QUOTED_TEXT__"><p>Hi Mika,<br>
    </p>
    <div class="moz-cite-prefix">On 6/22/22 1:58 PM, Mika Silander
      wrote:<br>
    </div>
    <blockquote>
      <pre class="moz-quote-pre"> Tracking down a rather elusive bug led me to suspect that the command

intelmqctl reload your_bot_name_here

 does not necessarily rerun the bot's init method.</pre>
    </blockquote>
    <p>It does, but not directly.</p>
    <p>reloading relies on sending a signal to the process. But signals
      interrupt system calls, which is normally not an issue, except the
      process is currently doing something on the network, more
      specifically with the pipeline (sending or receiving data). Let's
      assume that the bot sends an event to redis, get's interrupted.
      What to do now? Run init, and then? we can't just resume the
      previously running process() call. Therefore, the behaviour is not
      completely straighforward, but not magic.<br>
      The signal is caught (<span class="pl-en"><span class="pl-token">__handle_sighup_signal)</span></span>
      and python is commanded to resume system calls instead of
      interrupted (<span class="pl-s1"><span class="pl-token">signal</span></span>.<span class="pl-en"><span class="pl-token">siginterrupt</span></span>(<span class="pl-s1"><span class="pl-token">signal</span></span>.<span class="pl-v"><span class="pl-token">SIGHUP</span></span>,
      <span class="pl-c1">False</span>) in __init__)<br>
      Once there is time to handle the reload safely (before/after
      process, during sleeps, when waiting for messages), the bot is
      actually reloaded and __init__ called (<span class="pl-en"><span class="pl-token active">__handle_sighup).</span></span></p>
    <blockquote>
      <pre class="moz-quote-pre">At least I see an exception related to undefined variables (NoneType)</pre>
    </blockquote>
    In the code of the core or in the bot's code? If it's the bot's
    code: What bot is it? In any case, the stacktrace helps in
    explaining the issue, because unfortunately crystal ball broke last
    night when my neighbors' dragon chased my little dinosaur....<br>
    <blockquote>
      <pre class="moz-quote-pre">when I reload the bot in question and let it chew a new event. Is this expected behaviour? Still, skimming through the code, it seems to me that the __init__ method in lib/bot.py gets invoked and should invoke the bot's init method as well.</pre>
    </blockquote>
    <p>Yes, it shoud/does:</p>
    <p><a href="https://github.com/certtools/intelmq/blob/79cae294a74ab77f09b1f371a19f04ad65abab12/intelmq/lib/bot.py#L216" target="_blank" rel="nofollow noopener noreferrer">https://github.com/certtools/intelmq/blob/79cae294a74ab77f09b1f371a19f04ad65abab12/intelmq/lib/bot.py#L216</a>
    </p>
    <blockquote>
    </blockquote>
    <pre class="moz-signature">-- 
Institute for Common Good Technology
<a href="http://commongoodtechnology.org/" target="_blank" rel="nofollow noopener noreferrer">http://commongoodtechnology.org/</a>
ZVR 1510673578</pre><br></div></div></body></html>