Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activegraph hangs when a transaction encounters a neo4j deadlock #1664

Open
efivash opened this issue Oct 27, 2021 · 0 comments
Open

Activegraph hangs when a transaction encounters a neo4j deadlock #1664

efivash opened this issue Oct 27, 2021 · 0 comments

Comments

@efivash
Copy link

efivash commented Oct 27, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant