Last active
September 23, 2020 19:17
-
-
Save HarlemSquirrel/ad69c7745b1ed2950206e231e5b73b48 to your computer and use it in GitHub Desktop.
Reproduce ActiveLdap thread-safe issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# 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