Skip to content

Activegraph hangs when a transaction encounters a neo4j deadlock #1664

@efivash

Description

@efivash

It appears that when newer versions activegraph encounter a deadlock, they hang and no longer responds to signals, meaning the process needs to be kill -9'd. I encountered this in the wild on centos 7 but was able to replicate the hang on osx. This issue did not occur prior to the swap to neo4j-ruby-driver that occurred in 10.x. I do not believe this is related to the thread-saftey issue reported in #1620 as it can occur when a single thread deadlocks with a transaction from another process.

Code example (inline, gist, or repo)

The 'hang' method in the following code run on a fresh db with UUID constraints set for Foo and Bar will replicate the issue.

Note that despite this being a threaded method, this will still occur if you remove the thread block and run 2 instances of the hang method in different processes.

require 'neo4j_ruby_driver'
require 'active_graph/core'
require 'active_graph'
class Foo
  include ActiveGraph::Node
  property :name, type: String
  has_many :out, :bars, type: :foo_bar, model_class: 'Bar', unique: true
  end
class Bar
  include ActiveGraph::Node
  property :name, type: String
  has_one :in, :foo, type: :foo_bar, model_class: 'Foo', unique: true
end
module Hang
  def setup
    ActiveGraph::Base.driver = Neo4j::Driver::GraphDatabase.driver('bolt://localhost:7687', Neo4j::Driver::AuthTokens.basic('neo4j', ''), encryption: false)
  end

  def hang
    setup
    threads = (1..5).map do |n|
      Thread.new do
        (1..100).each do |m|
          ActiveGraph::Base.write_transaction do
            foo = Foo.find_or_create_by(name: 'test-hang')
            Bar.create(foo: foo, name: "#{n}-#{m}-#{Time.now.to_i}")
          end
          puts "thread: #{n} loop: #{m}"
        end
      end
    end
    threads.map(&:join)
  end
end

Runtime information:

OS: Found initially on Centos7 replicated on OSX 11.6
Ruby: 2.7.2
Neo4j database version: 3.5.19-1
acrivegraph gem version: 10.1.0
neo4j-ruby-driver gem version: 1.7.5 (ffi)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions