Skip to content

Commit e03549d

Browse files
historian: don't crash on rabbitmq stream loss
1 parent 46cc7e5 commit e03549d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

archived/historian/historian.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,22 +297,30 @@ def publish(self, raw: bytes) -> None:
297297
gossipd.ChannelAnnouncement,
298298
gossipd.NodeAnnouncement]:
299299
if isinstance(msg, msg_type):
300-
self.channel.basic_publish(exchange='router.gossip',
301-
# unused by fanout exchange
302-
routing_key='',
303-
body=serialize(raw, self.node_id,
304-
self.network))
300+
try:
301+
self.channel.basic_publish(exchange='router.gossip',
302+
# unused by fanout exchange
303+
routing_key='',
304+
body=serialize(raw, self.node_id,
305+
self.network))
306+
307+
except pika.exceptions.StreamLostError:
308+
plugin.log("lost connection to rabbitmq, reconnecting")
309+
self.rabbitmq_connect()
305310
return
306311

307312

308313

309314
@plugin.init()
310315
def init(plugin, configuration, options):
311316
print(options)
312-
with create_engine(options['historian-dsn'], echo=False) as engine:
317+
try:
318+
engine = create_engine(options['historian-dsn'], echo=False)
313319
Base.metadata.create_all(engine)
314320
plugin.engine = engine
315321
Flusher(engine).start()
322+
finally:
323+
engine.dispose()
316324

317325

318326
@plugin.method('historian-stats')

0 commit comments

Comments
 (0)