2

我正在尝试测试一个 Apache 模块。我正在使用一个打开 HTTP 连接并在服务器上发送数千个 json 数据包的 python 脚本。每个数据包都是一个单独的请求。问题是我相信我在 apache 中遇到了堆栈溢出,这显然会导致它崩溃。这是 gdb 输出:

#0  0x00007ffff7ffb8d4 in gettimeofday ()
#1  0x00007ffff776fa58 in apr_time_now () from /usr/lib/libapr-1.so.0
#2  0x00007ffff56dcaed in ?? () from /usr/lib/x86_64-linux-gnu/mod_reqtimeout.so
#3  0x00007ffff56dcd84 in ?? () from /usr/lib/x86_64-linux-gnu/mod_reqtimeout.so
#4  0x00007ffff56dcd84 in ?? () from /usr/lib/x86_64-linux-gnu/mod_reqtimeout.so
#5  0x00007ffff56dcd84 in ?? () from /usr/lib/x86_64-linux-gnu/mod_reqtimeout.so
#6  0x00007ffff56dcd84 in ?? () from /usr/lib/x86_64-linux-gnu/mod_reqtimeout.so
#7  0x00007ffff56dcd84 in ?? () from /usr/lib/x86_64-linux-gnu/mod_reqtimeout.so
#8  0x00007ffff56dcd84 in ?? () from /usr/lib/x86_64-linux-gnu/mod_reqtimeout.so
#9  0x00007ffff56dcd84 in ?? () from /usr/lib/x86_64-linux-gnu/mod_reqtimeout.so
#10 0x00007ffff56dcd84 in ?? () from /usr/lib/x86_64-linux-gnu/mod_reqtimeout.so
...
#43661 0x00007ffff56dcd84 in ?? () from /usr/lib/x86_64-linux-gnu/mod_reqtimeout.so
#43662 0x00007ffff56dcd84 in ?? () from /usr/lib/x86_64-linux-gnu/mod_reqtimeout.so
#43663 0x000000000045c68d in ap_http_filter ()
#43664 0x00007ffff3c9cc82 in apreq_filter_prefetch () from /usr/lib/x86_64-linux-gnu/mod_apreq2.so
#43665 0x00007ffff3c9ba33 in ?? () from /usr/lib/x86_64-linux-gnu/mod_apreq2.so
#43666 0x00007ffff3a92b4b in ?? () from /usr/lib/x86_64-linux-gnu/libapreq2.so.3
#43667 0x00007ffff3a92b8e in apreq_param () from /usr/lib/x86_64-linux-gnu/libapreq2.so.3
#43668 0x00007ffff36672e3 in rtb_handler (r=0x7fff7045f0a0) at /home/james/mymodule.cpp:550
#43669 0x00000000004479a8 in ap_run_handler ()
#43670 0x0000000000447dfe in ap_invoke_handler ()
#43671 0x000000000045b60a in ap_process_async_request ()
#43672 0x0000000000458437 in ?? ()
#43673 0x0000000000450b28 in ap_run_process_connection ()
#43674 0x000000000046307b in ?? ()
#43675 0x00007ffff776f417 in ?? () from /usr/lib/libapr-1.so.0
#43676 0x00007ffff752be9a in start_thread (arg=0x7fff557d2700) at pthread_create.c:308
#43677 0x00007ffff7258ccd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#43678 0x0000000000000000 in ?? ()

mymodule.cpp 的第 550 行在处理程序中:

apreq_handle_t *req = apreq_handle_apache2(r);

帧数可疑地接近我在 SIGSEGV 发生之前发送的数据包数。

python脚本本质上是:

def main():
   conn = httplib.HTTPConnection("127.0.0.1", 8080)
   headers = {
       "Content-type": "application/json",
       "Accept": "text/plain",
       "Connection": "keep-alive"
   }

   with open("logfile.txt") as f:
       packets = f.readlines()

       for packet in packets:
           conn.request("POST", "/url", packet, headers)
           response = conn.getresponse()
           data = response.read()

   conn.close()

在模块中,解析请求正文所需的时间线性增加,但我在我们的代码中找不到任何递归。所以我被困住了。也许 mod_reqtimeout 模块与 Keep-Alive 连接不兼容,或者我的测试脚本有问题?

编辑:从 httpd.conf 中删除 mod_reqtimeout 似乎可以解决问题。我面临的另一个问题是,如果测试脚本被杀死,apache 也会收到 SIGHUP。我怎样才能阻止这种情况发生?

4

0 回答 0