Skip to content

Commit

Permalink
Fix deadlock in Client#on_ready
Browse files Browse the repository at this point in the history
  • Loading branch information
vladislav-yashin committed Apr 27, 2018
1 parent ceab4c8 commit 97d7479
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
### 0.9.0 / 2018-04-25
### 0.9.1 / 2018-04-27

* Fix deadlock in Client#on_ready

### 0.9.0 / 2018-04-26

* Use Celluloid

### 0.8.0 / 2018-04-25
Expand Down
8 changes: 4 additions & 4 deletions lib/tdlib/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def initialize(td_client = TD::Api.client_create,
@td_client = td_client
@update_manager = update_manager
@config = TD.config.client.to_h.merge(extra_config)
@ready = Celluloid::Condition.new
@ready_condition = Celluloid::Condition.new
authorize
@update_manager.run
end
Expand Down Expand Up @@ -128,8 +128,7 @@ def on(update_type, &_)
end

def on_ready(timeout: TIMEOUT, &_)
@ready.wait(timeout)
yield self
yield self if @ready || @ready_condition.wait(timeout)
rescue Celluloid::ConditionError
raise TD::TimeoutError
end
Expand Down Expand Up @@ -164,7 +163,8 @@ def authorize
broadcast(encryption_key_query)
else
@update_manager.remove_handler(handler)
@ready.signal(true)
@ready = true
@ready_condition.signal(true)
end
end
@update_manager.add_handler(handler)
Expand Down
2 changes: 1 addition & 1 deletion lib/tdlib/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module TD
# tdlib-ruby version
VERSION = "0.9.0"
VERSION = "0.9.1"
end
2 changes: 1 addition & 1 deletion spec/integration/tdlib_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
end

describe '#broadcast_and_receive' do
subject { client.on_ready { client.broadcast_and_receive(payload ) } }
subject { client.on_ready { client.broadcast_and_receive(payload) } }

it { is_expected.to include('@type', 'entities') }
end
Expand Down

0 comments on commit 97d7479

Please sign in to comment.