Ticket #5763 (closed Patches: fixed)

Opened 4 years ago

Last modified 3 years ago

Segmentation fault in ASIO signal handler

Reported by: Vladislav <phprus@…> Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc:



I am using boost asio 1.47.0 to system signal handler. If using compiler Intel Composer XE 12.0.1 and optimization level greater -01 segmentation fault occurs in file boost/asio/detail/signal_handler.hpp:67. In code line:

boost_asio_handler_invoke_helpers::invoke(handler, handler.handler_);

If insert before this line "sleep(0)" or write to stdout ASIO work normal. If using GCC 4.1.2, 4.3.4, 4.5.0, 4.6.1(MinGW) and Intel C++ 11.1 code work normal.

I noticed that the ICC and GCC use different versions of fenced_block and replaced gcc_x86_fenced_block to gcc_sync_fenced_block in ICC then error is gone.

Function sync_lock_test_and_set is available in the ICC since version 11.0, I wrote the appropriate patch.


boost_1_47_0-intel-segfault-in-asio-signal.diff Download (2.7 KB) - added by Vladislav <phprus@…> 4 years ago.

Change History

Changed 4 years ago by Vladislav <phprus@…>

comment:1 Changed 4 years ago by Vladislav <phprus@…>

Sorry. Typo in compiler version. Compiler Intel Composer XE 12.0.4

comment:2 Changed 4 years ago by chris_kohlhoff

Thank you for providing a patch. However, without a test case, I cannot confirm that this is the correct fix. Can you please supply a small test program that can be used to reproduce the error.

comment:3 Changed 4 years ago by chris_kohlhoff

  • Severity changed from Regression to Problem
  • Milestone changed from Boost 1.48.0 to To Be Determined

comment:4 Changed 4 years ago by Vladislav <phprus@…>

Test case: "HTTP Server" Segmentation fault on recived SIGINT.

comment:5 Changed 4 years ago by chris_kohlhoff

Please also specify the target platform, architecture (32 or 64 bit) and compiler command line used.

comment:6 Changed 4 years ago by Vladislav <phprus@…>

Problem platform: openSUSE 11.3 x86 (32 bit)

Boost built by system gcc 4.5.0, application is built by Intel 12.0.4

Command line:

icpc -O3 -g -lboost_thread -lboost_system *.cpp


icpc -gxx-name=g++-4.3 -O3 -g -lboost_thread -lboost_system *.cpp

comment:7 Changed 4 years ago by chris_kohlhoff

I was able to reproduce the issue, and I believe the correct fix is to apply the following change to asio/include/asio/detail/gcc_x86_fenced_block.hpp:

@@ -43,8 +43,12 @@ public:
   static int barrier()
-    int r = 0;
-    __asm__ __volatile__ ("xchgl %%eax, %0" : "=m" (r) : : "memory", "cc");
+    int r = 0, m = 1;
+    __asm__ __volatile__ (
+        "xchgl %0, %1" :
+        "=r"(r), "=m"(m) :
+        "0"(1), "m"(m) :
+        "memory", "cc");
     return r;

Can you please try this change and let me know if it also corrects the issue for you.

Note that using the gcc_sync_fenced_block class does improve performance slightly, so I will also look to include your patch in the near future.

comment:8 Changed 4 years ago by Vladislav <phprus@…>

Your patch fixes a bug.

comment:9 Changed 4 years ago by Vladislav <phprus@…>

Tell please how there are affairs with bug fix?

comment:10 Changed 3 years ago by Vladislav <phprus@…>

Tell please how there are affairs with bug fix?

comment:11 Changed 3 years ago by chris_kohlhoff

(In [74822]) Fix crash due to gcc_x86_fenced_block that shows up when using the Intel C++ compiler. Refs #5763

comment:12 Changed 3 years ago by chris_kohlhoff

  • Status changed from new to closed
  • Resolution set to fixed

(In [74863]) Merge from trunk...

Fix compile error in regex overload of async_read_until.hpp. Fixes #5688

Explicitly specify the signal() function from the global namespace. Fixes #5722

Don't read the clock unless the heap is non-empty.

Change the SSL buffers sizes so that they're large enough to hold a complete TLS record. Fixes #5854

Make sure the synchronous null_buffers operations obey the user's non_blocking setting. Fixes #5756

Set size of select fd_set at runtime when using Windows.

Disable warning due to const qualifier being applied to function type.

Fix crash due to gcc_x86_fenced_block that shows up when using the Intel C++ compiler. Fixes #5763

Specialise operations for buffer sequences that are arrays of exactly two buffers.

Initialise all OpenSSL algorithms.

Fix error mapping when session is gracefully shut down.

Various performance improvements:

  • Split the task_io_service's run and poll code.
  • Use thread-local operation queues in single-threaded use cases (i.e. concurrency_hint is 1) to eliminate a lock/unlock pair.
  • Only fence block exit when a handler is being run directly out of the io_service.
  • Prefer x86 mfence-based fenced block when available.
  • Use a plain ol' long for the atomic_count when all thread support is disabled.
  • Allow some epoll_reactor speculative operations to be performed without holding the lock.
  • Improve locality of reference by performing an epoll_reactor's I/O operation immediately before the corresponding handler is called. This also improves scalability across CPUs when multiple threads are running the io_service.
  • Pass same error_code variable through to each operation's complete() function.
  • Optimise creation of and access to the io_service implementation.

Remove unused state in HTTP server examples.

Add latency test programs.


Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.