<div dir="ltr"><div dir="ltr"><div dir="ltr">Thanks for the prompt reply. Yes I do have TLS enabled and in fact the crash is inside one of the TCP receiver processes when it is handing a REGISTER message.<div><br></div><div>I will try with non TLS connections, however it is intermittent so the absence of crashes hasn't always been a good guide. Also I really need TLS for the client connections.</div><div><br></div><div>I might try something else first though. From Boto3 docs :</div><div><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div dir="ltr"><div>The boto3 module acts as a proxy to the default session</div><div><br></div><div>A session manages state about a particular configuration. By default a session is created for you when needed. However it is possible and recommended to maintain your own session(s) in some scenarios. </div><div><br></div><div>It is also possible to manage your own session and create clients or resources from it:</div><div><br></div><div># Creating your own session</div><div>session = boto3.session.Session()</div><div><br></div><div>sqs = session.client('sqs')</div><div>s3 = session.resource('s3')</div><div><br></div><div>Multithreading / Multiprocessing<br></div><div>--------------------------------</div><div>It is recommended to create a resource instance for each thread / process in a multithreaded or multiprocess application rather than sharing a single instance among the threads / processes. For example:</div><div><br></div><div>import boto3</div><div>import boto3.session</div><div>import threading</div><div><br></div><div>class MyTask(threading.Thread):</div><div> def run(self):</div><div> session = boto3.session.Session()</div><div> s3 = session.resource('s3')</div><div> # ... do some work with S3 ...</div><div><br></div><div><br></div><div>In the example above, each thread would have its own Boto 3 session and its own instance of the S3 resource. This is a good idea because resources contain shared data when loaded and calling actions, accessing properties, or manually loading or reloading the resource can modify this data.</div></div></blockquote><br></div><div dir="ltr"><br></div><div>So I could in __init__() initialise thus</div><div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>self.session = null</div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>self.sns_client = null</div></blockquote><br></div><div>and on demand from child processes :</div><div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>if not self.session:</div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div> self.session = boto3.session.Session(region_name=MY_AWS_REGION,use_ssl=True)</div><div><br></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>if not self.client:</div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div> self.sns_client = self.session.resource('sns')</div><div><br></div></blockquote><div>So each child process that need it gets it's own boto3 session.</div><div><br></div>Another thing I can try is setting use_ssl=False.</div><div><br></div><div>Cheers</div><div>Mike</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 10 Apr 2019 at 03:34, Daniel-Constantin Mierla <<a href="mailto:miconda@gmail.com">miconda@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<p>Hello,</p>
<p>do you have tls module loaded in kamailio.cfg? If yes, can you
try without it, just to see if there is a conflict between our
module and the boto3 client in use of libssl, because libssl
creates global contexts per application, not per library/object.</p>
<p>Cheers,<br>
Daniel<br>
</p>
<div class="gmail-m_1108884272147598381moz-cite-prefix">On 10.04.19 01:26, Michael Loughrey
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Hi All,
<div><br>
</div>
<div>looking for some advice regarding the proper way to
initialise an AWS API boto3 client object for send SNS
messages within a KEMI Python 2.7 routing script. </div>
<div><br>
</div>
<div>
<div>I'm sure process forking has a major impact on
how this works - from kamailio.cfg</div>
<div><br>
</div>
<div>
<div> fork=yes</div>
<div> children=4</div>
</div>
<div><br>
</div>
<div>- but would greatly appreciate some guidance.<br>
</div>
<br class="gmail-m_1108884272147598381m_-6381022331019216535gmail-Apple-interchange-newline">
</div>
<div>I have tried various methods to allocate an client
object self.sns_client = boto3.client('sns',
region_name=MY_AWS_REGION)</div>
<div><br>
</div>
<div> 1. within __init__(), only once from module
initialisation</div>
<div> 2. on demand within a function call by any client
code e.g. called from ksr_route_request(), each
creating it's own client object</div>
<div><br>
</div>
<div> and so far all have resulted in intermittent
crashes within botocore/client.py ultimately crashing
thus :</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div>Core was generated by `/usr/local/sbin/kamailio
-P /usr/local/kamailio/run/kamailio.pid -f
/usr/local/'.</div>
<div>Program terminated with signal SIGSEGV,
Segmentation fault.</div>
<div>#0 0x00007f8f9734f754 in ?? () from
/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1</div>
<div>(gdb) bt</div>
<div>#0 0x00007f8f9734f754 in ?? () from
/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1</div>
<div>#1 0x00007f8f9734f82e in X509_VERIFY_PARAM_free
() from /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1</div>
<div>#2 0x00007f8f97642f5c in SSL_free () from
/usr/lib/x86_64-linux-gnu/libssl.so.1.1</div>
<div>#3 0x00007f8f86b09c64 in
PySSL_dealloc.lto_priv.5 () at ./Modules/_ssl.c:1598</div>
<div>#4 0x00007f8f99cbb007 in insertdict_by_entry
(mp=0x7f8f841f1e88, key='_sslobj',
hash=<optimized out>, ep=<optimized
out>, value=<optimized out>) at
../Objects/dictobject.c:519</div>
<div>#5 0x00007f8f99cbe2cf in insertdict (value=None,
hash=1051385741686792393, key='_sslobj',
mp=0x7f8f841f1e88) at ../Objects/dictobject.c:556</div>
<div>#6 dict_set_item_by_hash_or_entry (value=None,
ep=0x0, hash=1051385741686792393, key='_sslobj', </div>
<div> op={'server_hostname': u'<a href="http://sns.us-east-1.amazonaws.com" target="_blank">sns.us-east-1.amazonaws.com</a>',
'_connected': True, '_context': <SSLContext at
remote 0x7f8f84232398>, 'server_side': False,
'_makefile_refs': 0, '_closed': False, '_sslobj':
None, 'do_handshake_on_connect': True,
'suppress_ragged_eofs': True}) at
../Objects/dictobject.c:795</div>
<div>#7 PyDict_SetItem (op=<optimized out>,
key=<optimized out>, value=<optimized
out>) at ../Objects/dictobject.c:848</div>
<div>#8 0x00007f8f99becec1 in
_PyObject_GenericSetAttrWithDict (obj=<optimized
out>, name='_sslobj', value=None, </div>
<div> dict={'server_hostname': u'<a href="http://sns.us-east-1.amazonaws.com" target="_blank">sns.us-east-1.amazonaws.com</a>',
'_connected': True, '_context': <SSLContext at
remote 0x7f8f84232398>, 'server_side': False,
'_makefile_refs': 0, '_closed': False, '_sslobj':
None, 'do_handshake_on_connect': True,
'suppress_ragged_eofs': True}) at
../Objects/object.c:1529</div>
<div>#9 0x00007f8f99bed437 in PyObject_SetAttr (</div>
<div> v=<SSLSocket(server_hostname=u'<a href="http://sns.us-east-1.amazonaws.com" target="_blank">sns.us-east-1.amazonaws.com</a>',
_connected=True, _context=<SSLContext at remote
0x7f8f84232398>, server_side=False,
_makefile_refs=0, _closed=False, _sslobj=None,
do_handshake_on_connect=True,
suppress_ragged_eofs=True) at remote
0x7f8f841f62a8>, name=<optimized out>,
value=None) at ../Objects/object.c:1247</div>
</div>
<div><br>
</div>
<div>Here's my setup<br>
</div>
<div>
<div>
<div><br>
</div>
<div>host : Debian9/stretch</div>
<div><br>
</div>
<div>
<div>python --version</div>
<div>Python 2.7.13</div>
<div><br>
</div>
<div>kamailio -v</div>
<div>version: kamailio 5.2.2 (x86_64/linux)
67f967-dirty</div>
<div>flags: STATS: Off, USE_TCP, USE_TLS,
USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS,
DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM,
SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC,
TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX,
FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE,
USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST,
HAVE_RESOLV_RES, MEM_JOIN_FREE</div>
<div>ADAPTIVE_WAIT_LOOPS=1024,
MAX_RECV_BUFFER_SIZE 262144 MAX_URI_SIZE 1024,
BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB</div>
<div>poll method support: poll, epoll_lt,
epoll_et, sigio_rt, select.</div>
<div>id: 67f967 -dirty</div>
<div>compiled on 23:44:31 Apr 8 2019 with gcc
6.3.0</div>
</div>
</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Cheers</div>
<div>Mike</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset class="gmail-m_1108884272147598381mimeAttachmentHeader"></fieldset>
<pre class="gmail-m_1108884272147598381moz-quote-pre">_______________________________________________
Kamailio (SER) - Users Mailing List
<a class="gmail-m_1108884272147598381moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a>
<a class="gmail-m_1108884272147598381moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
</blockquote>
<pre class="gmail-m_1108884272147598381moz-signature" cols="72">--
Daniel-Constantin Mierla -- <a class="gmail-m_1108884272147598381moz-txt-link-abbreviated" href="http://www.asipto.com" target="_blank">www.asipto.com</a>
<a class="gmail-m_1108884272147598381moz-txt-link-abbreviated" href="http://www.twitter.com/miconda" target="_blank">www.twitter.com/miconda</a> -- <a class="gmail-m_1108884272147598381moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda" target="_blank">www.linkedin.com/in/miconda</a>
Kamailio World Conference - May 6-8, 2019 -- <a class="gmail-m_1108884272147598381moz-txt-link-abbreviated" href="http://www.kamailioworld.com" target="_blank">www.kamailioworld.com</a></pre>
</div>
</blockquote></div>