Skip to content

Instantly share code, notes, and snippets.

@HarlemSquirrel
Last active September 23, 2020 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HarlemSquirrel/ad69c7745b1ed2950206e231e5b73b48 to your computer and use it in GitHub Desktop.
Save HarlemSquirrel/ad69c7745b1ed2950206e231e5b73b48 to your computer and use it in GitHub Desktop.
Reproduce ActiveLdap thread-safe issue
##
# This can reproduce https://github.com/activeldap/activeldap/issues/186
#
# Uses OpenLDAP Docker container
# docker run -p 1389:389 --name activeldap-test --detach osixia/openldap
#
require 'active_ldap'
class User < ActiveLdap::Base
setup_connection host: 'localhost',
port: 1389,
bind_dn: 'cn=admin,dc=example,dc=org',
password: 'admin',
base: 'dc=example,dc=org'
ldap_mapping dn_attribute: 'cn', classes: [], prefix: ''
end
puts "Schema attribute count: #{User.schema.attributes.length}"
threads = []
20.times do
threads << Thread.new do
sleep(rand(0.1..2))
User.connection.unbind
puts 'unbound'
end
end
20.times do
threads << Thread.new do
sleep(rand(0.1..2))
puts "First user: #{User.all.first.dn}"
rescue NoMethodError => e
puts "==> #{e.class}: #{e.message}"
end
end
threads.each(&:join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment