summaryrefslogtreecommitdiff
path: root/net-analyzer/icinga2/files/icinga2-2.14.5-boost-1.87.patch
blob: 1c208f983a84c5bfda805cbd061eda7cf2c8d20c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
https://bugs.gentoo.org/946671
https://github.com/Icinga/icinga2/pull/10278

From 69e4f295a6bd5cdafb295379b207ab611c8501a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexander=20Aleksandrovi=C4=8D=20Klimov?=
 <al2klimov@gmail.com>
Date: Tue, 7 Jan 2025 15:53:20 +0100
Subject: [PATCH 2/5] Don't use boost::asio::ip::tcp::resolver::query

It was removed in Boost 1.87.
---
 lib/base/tcpsocket.hpp     | 6 ++----
 lib/remote/apilistener.cpp | 4 +---
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/lib/base/tcpsocket.hpp b/lib/base/tcpsocket.hpp
index 471ad8d2394..1cf1a235010 100644
--- a/lib/base/tcpsocket.hpp
+++ b/lib/base/tcpsocket.hpp
@@ -41,8 +41,7 @@ void Connect(Socket& socket, const String& node, const String& service)
 	using boost::asio::ip::tcp;
 
 	tcp::resolver resolver (IoEngine::Get().GetIoContext());
-	tcp::resolver::query query (node, service);
-	auto result (resolver.resolve(query));
+	auto result (resolver.resolve(node.CStr(), service.CStr()));
 	auto current (result.begin());
 
 	for (;;) {
@@ -72,8 +71,7 @@ void Connect(Socket& socket, const String& node, const String& service, boost::a
 	using boost::asio::ip::tcp;
 
 	tcp::resolver resolver (IoEngine::Get().GetIoContext());
-	tcp::resolver::query query (node, service);
-	auto result (resolver.async_resolve(query, yc));
+	auto result (resolver.async_resolve(node.CStr(), service.CStr(), yc));
 	auto current (result.begin());
 
 	for (;;) {
diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp
index 519469aafa4..7ef3acddda7 100644
--- a/lib/remote/apilistener.cpp
+++ b/lib/remote/apilistener.cpp
@@ -439,9 +439,7 @@ bool ApiListener::AddListener(const String& node, const String& service)
 
 	try {
 		tcp::resolver resolver (io);
-		tcp::resolver::query query (node, service, tcp::resolver::query::passive);
-
-		auto result (resolver.resolve(query));
+		auto result (resolver.resolve(node.CStr(), service.CStr(), tcp::resolver::passive));
 		auto current (result.begin());
 
 		for (;;) {

From 6e1bafad83a1d5cbd646a947575b29f00c23d130 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexander=20Aleksandrovi=C4=8D=20Klimov?=
 <alexander.klimov@icinga.com>
Date: Tue, 7 Jan 2025 17:53:42 +0100
Subject: [PATCH 3/5] Don't use boost::asio::io_context::strand method removed
 in Boost 1.87

---
 lib/remote/jsonrpcconnection.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp
index d49c0b359a0..8e95325feb3 100644
--- a/lib/remote/jsonrpcconnection.cpp
+++ b/lib/remote/jsonrpcconnection.cpp
@@ -212,7 +212,7 @@ void JsonRpcConnection::SendMessage(const Dictionary::Ptr& message)
 
 	Ptr keepAlive (this);
 
-	m_IoStrand.post([this, keepAlive, message]() { SendMessageInternal(message); });
+	boost::asio::post(m_IoStrand, [this, keepAlive, message] { SendMessageInternal(message); });
 }
 
 void JsonRpcConnection::SendRawMessage(const String& message)
@@ -223,7 +223,7 @@ void JsonRpcConnection::SendRawMessage(const String& message)
 
 	Ptr keepAlive (this);
 
-	m_IoStrand.post([this, keepAlive, message]() {
+	boost::asio::post(m_IoStrand, [this, keepAlive, message] {
 		if (m_ShuttingDown) {
 			return;
 		}

From 5e058f46289f603338d02ad61524886d6cc3e26a Mon Sep 17 00:00:00 2001
From: "Alexander A. Klimov" <alexander.klimov@icinga.com>
Date: Fri, 7 Mar 2025 16:22:50 +0100
Subject: [PATCH 4/5] In a coroutine, re-throw everything ex. std::exception
 (and inheritors)

not just boost::coroutines::detail::forced_unwind.

This is needed because as of Boost 1.87, boost::asio::spawn() uses Fiber, not Coroutine v1.
https://github.com/boostorg/asio/commit/df973a85ed69f021

This is safe because every actual exception shall inherit from std::exception. Except forced_unwind and its Fiber equivalent, so that `catch(const std::exception&)` doesn't catch them and only them.
---
 lib/base/io-engine.hpp           | 13 ++++++----
 lib/icingadb/redisconnection.cpp | 41 ++++----------------------------
 lib/icingadb/redisconnection.hpp |  8 ++-----
 3 files changed, 14 insertions(+), 48 deletions(-)

diff --git a/lib/base/io-engine.hpp b/lib/base/io-engine.hpp
index 0350d45b83d..55a06fb6a67 100644
--- a/lib/base/io-engine.hpp
+++ b/lib/base/io-engine.hpp
@@ -106,14 +106,17 @@ class IoEngine
 
 				try {
 					f(yc);
-				} catch (const boost::coroutines::detail::forced_unwind &) {
-					// Required for proper stack unwinding when coroutines are destroyed.
-					// https://github.com/boostorg/coroutine/issues/39
-					throw;
 				} catch (const std::exception& ex) {
 					Log(LogCritical, "IoEngine") << "Exception in coroutine: " << DiagnosticInformation(ex);
 				} catch (...) {
-					Log(LogCritical, "IoEngine", "Exception in coroutine!");
+					try {
+						Log(LogCritical, "IoEngine", "Exception in coroutine!");
+					} catch (...) {
+					}
+
+					// Required for proper stack unwinding when coroutines are destroyed.
+					// https://github.com/boostorg/coroutine/issues/39
+					throw;
 				}
 			},
 			boost::coroutines::attributes(GetCoroutineStackSize()) // Set a pre-defined stack size.
diff --git a/lib/icingadb/redisconnection.cpp b/lib/icingadb/redisconnection.cpp
index a6b82187dd0..c1f73f5a0e6 100644
--- a/lib/icingadb/redisconnection.cpp
+++ b/lib/icingadb/redisconnection.cpp
@@ -377,8 +377,6 @@ void RedisConnection::Connect(asio::yield_context& yc)
 			}
 
 			break;
-		} catch (const boost::coroutines::detail::forced_unwind&) {
-			throw;
 		} catch (const std::exception& ex) {
 			Log(LogCritical, "IcingaDB")
 				<< "Cannot connect to " << m_Host << ":" << m_Port << ": " << ex.what();
@@ -408,17 +406,10 @@ void RedisConnection::ReadLoop(asio::yield_context& yc)
 						for (auto i (item.Amount); i; --i) {
 							ReadOne(yc);
 						}
-					} catch (const boost::coroutines::detail::forced_unwind&) {
-						throw;
 					} catch (const std::exception& ex) {
 						Log(LogCritical, "IcingaDB")
 							<< "Error during receiving the response to a query which has been fired and forgotten: " << ex.what();
 
-						continue;
-					} catch (...) {
-						Log(LogCritical, "IcingaDB")
-							<< "Error during receiving the response to a query which has been fired and forgotten";
-
 						continue;
 					}
 
@@ -432,9 +423,7 @@ void RedisConnection::ReadLoop(asio::yield_context& yc)
 
 						try {
 							reply = ReadOne(yc);
-						} catch (const boost::coroutines::detail::forced_unwind&) {
-							throw;
-						} catch (...) {
+						} catch (const std::exception&) {
 							promise.set_exception(std::current_exception());
 
 							continue;
@@ -455,9 +444,7 @@ void RedisConnection::ReadLoop(asio::yield_context& yc)
 						for (auto i (item.Amount); i; --i) {
 							try {
 								replies.emplace_back(ReadOne(yc));
-							} catch (const boost::coroutines::detail::forced_unwind&) {
-								throw;
-							} catch (...) {
+							} catch (const std::exception&) {
 								promise.set_exception(std::current_exception());
 								break;
 							}
@@ -551,19 +538,11 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection:
 
 		try {
 			WriteOne(item, yc);
-		} catch (const boost::coroutines::detail::forced_unwind&) {
-			throw;
 		} catch (const std::exception& ex) {
 			Log msg (LogCritical, "IcingaDB", "Error during sending query");
 			LogQuery(item, msg);
 			msg << " which has been fired and forgotten: " << ex.what();
 
-			return;
-		} catch (...) {
-			Log msg (LogCritical, "IcingaDB", "Error during sending query");
-			LogQuery(item, msg);
-			msg << " which has been fired and forgotten";
-
 			return;
 		}
 
@@ -587,19 +566,11 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection:
 				WriteOne(query, yc);
 				++i;
 			}
-		} catch (const boost::coroutines::detail::forced_unwind&) {
-			throw;
 		} catch (const std::exception& ex) {
 			Log msg (LogCritical, "IcingaDB", "Error during sending query");
 			LogQuery(item[i], msg);
 			msg << " which has been fired and forgotten: " << ex.what();
 
-			return;
-		} catch (...) {
-			Log msg (LogCritical, "IcingaDB", "Error during sending query");
-			LogQuery(item[i], msg);
-			msg << " which has been fired and forgotten";
-
 			return;
 		}
 
@@ -618,9 +589,7 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection:
 
 		try {
 			WriteOne(item.first, yc);
-		} catch (const boost::coroutines::detail::forced_unwind&) {
-			throw;
-		} catch (...) {
+		} catch (const std::exception&) {
 			item.second.set_exception(std::current_exception());
 
 			return;
@@ -645,9 +614,7 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection:
 			for (auto& query : item.first) {
 				WriteOne(query, yc);
 			}
-		} catch (const boost::coroutines::detail::forced_unwind&) {
-			throw;
-		} catch (...) {
+		} catch (const std::exception&) {
 			item.second.set_exception(std::current_exception());
 
 			return;
diff --git a/lib/icingadb/redisconnection.hpp b/lib/icingadb/redisconnection.hpp
index 3f963f3d37d..acc6e43810c 100644
--- a/lib/icingadb/redisconnection.hpp
+++ b/lib/icingadb/redisconnection.hpp
@@ -389,9 +389,7 @@ RedisConnection::Reply RedisConnection::ReadOne(StreamPtr& stream, boost::asio::
 
 	try {
 		return ReadRESP(*strm, yc);
-	} catch (const boost::coroutines::detail::forced_unwind&) {
-		throw;
-	} catch (...) {
+	} catch (const std::exception&) {
 		if (m_Connecting.exchange(false)) {
 			m_Connected.store(false);
 			stream = nullptr;
@@ -427,9 +425,7 @@ void RedisConnection::WriteOne(StreamPtr& stream, RedisConnection::Query& query,
 	try {
 		WriteRESP(*strm, query, yc);
 		strm->async_flush(yc);
-	} catch (const boost::coroutines::detail::forced_unwind&) {
-		throw;
-	} catch (...) {
+	} catch (const std::exception&) {
 		if (m_Connecting.exchange(false)) {
 			m_Connected.store(false);
 			stream = nullptr;

From 62221b2d60078dda09463a0d5ed96f1fdbacdaf0 Mon Sep 17 00:00:00 2001
From: "Alexander A. Klimov" <alexander.klimov@icinga.com>
Date: Fri, 7 Mar 2025 15:47:37 +0100
Subject: [PATCH 5/5] Don't use removed boost::asio::spawn() overload if Boost
 >= v1.87

---
 lib/base/io-engine.hpp  | 13 +++++++++++++
 test/base-io-engine.cpp | 10 +++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/lib/base/io-engine.hpp b/lib/base/io-engine.hpp
index 55a06fb6a67..2083b62f87d 100644
--- a/lib/base/io-engine.hpp
+++ b/lib/base/io-engine.hpp
@@ -16,11 +16,16 @@
 #include <utility>
 #include <vector>
 #include <stdexcept>
+#include <boost/context/fixedsize_stack.hpp>
 #include <boost/exception/all.hpp>
 #include <boost/asio/deadline_timer.hpp>
 #include <boost/asio/io_context.hpp>
 #include <boost/asio/spawn.hpp>
 
+#if BOOST_VERSION >= 108700
+#	include <boost/asio/detached.hpp>
+#endif // BOOST_VERSION >= 108700
+
 namespace icinga
 {
 
@@ -102,6 +107,10 @@ class IoEngine
 	static void SpawnCoroutine(Handler& h, Function f) {
 
 		boost::asio::spawn(h,
+#if BOOST_VERSION >= 108700
+			std::allocator_arg,
+			boost::context::fixedsize_stack(GetCoroutineStackSize()),
+#endif // BOOST_VERSION >= 108700
 			[f](boost::asio::yield_context yc) {
 
 				try {
@@ -119,7 +128,11 @@ class IoEngine
 					throw;
 				}
 			},
+#if BOOST_VERSION >= 108700
+			boost::asio::detached
+#else // BOOST_VERSION >= 108700
 			boost::coroutines::attributes(GetCoroutineStackSize()) // Set a pre-defined stack size.
+#endif // BOOST_VERSION >= 108700
 		);
 	}
 
diff --git a/test/base-io-engine.cpp b/test/base-io-engine.cpp
index 869688b1a67..3a251b1b421 100644
--- a/test/base-io-engine.cpp
+++ b/test/base-io-engine.cpp
@@ -17,7 +17,7 @@ BOOST_AUTO_TEST_CASE(timeout_run)
 	boost::asio::io_context::strand strand (io);
 	int called = 0;
 
-	boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
+	IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) {
 		boost::asio::deadline_timer timer (io);
 
 		Timeout timeout (strand, boost::posix_time::millisec(300), [&called] { ++called; });
@@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(timeout_cancelled)
 	boost::asio::io_context::strand strand (io);
 	int called = 0;
 
-	boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
+	IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) {
 		boost::asio::deadline_timer timer (io);
 		Timeout timeout (strand, boost::posix_time::millisec(300), [&called] { ++called; });
 
@@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(timeout_scope)
 	boost::asio::io_context::strand strand (io);
 	int called = 0;
 
-	boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
+	IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) {
 		boost::asio::deadline_timer timer (io);
 
 		{
@@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(timeout_due_cancelled)
 	boost::asio::io_context::strand strand (io);
 	int called = 0;
 
-	boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
+	IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) {
 		boost::asio::deadline_timer timer (io);
 		Timeout timeout (strand, boost::posix_time::millisec(300), [&called] { ++called; });
 
@@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(timeout_due_scope)
 	boost::asio::io_context::strand strand (io);
 	int called = 0;
 
-	boost::asio::spawn(strand, [&](boost::asio::yield_context yc) {
+	IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) {
 		boost::asio::deadline_timer timer (io);
 
 		{