Opened 11 years ago

Closed 11 years ago

#5763 closed Patches (fixed)

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:

Description

Hello!

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.

Attachments (1)

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

Download all attachments as: .zip

Change History (13)

by Vladislav <phprus@…>, 11 years ago

comment:1 by Vladislav <phprus@…>, 11 years ago

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

comment:2 by chris_kohlhoff, 11 years ago

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 by chris_kohlhoff, 11 years ago

Milestone: Boost 1.48.0To Be Determined
Severity: RegressionProblem

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

Test case: http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/examples.html "HTTP Server" Segmentation fault on recived SIGINT.

comment:5 by chris_kohlhoff, 11 years ago

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

comment:6 by Vladislav <phprus@…>, 11 years ago

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

or

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

comment:7 by chris_kohlhoff, 11 years ago

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:
 private:
   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 by Vladislav <phprus@…>, 11 years ago

Your patch fixes a bug.

comment:9 by Vladislav <phprus@…>, 11 years ago

Tell please how there are affairs with bug fix?

comment:10 by Vladislav <phprus@…>, 11 years ago

Tell please how there are affairs with bug fix?

comment:11 by chris_kohlhoff, 11 years ago

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

comment:12 by chris_kohlhoff, 11 years ago

Resolution: fixed
Status: newclosed

(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.

Note: See TracTickets for help on using tickets.