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

Twilio class has a lot of multithreading issues. #430

Closed
bohnman opened this issue Jul 24, 2018 · 2 comments · Fixed by #588
Closed

Twilio class has a lot of multithreading issues. #430

bohnman opened this issue Jul 24, 2018 · 2 comments · Fixed by #588
Labels
type: twilio enhancement feature request on Twilio's roadmap

Comments

@bohnman
Copy link

bohnman commented Jul 24, 2018

Version:

7.22.0

Steps to Reproduce

The Twilio class has a bunch of multithreading issues. I fundamentally disagree with using singletons that are mutable, but if you're going to do it, it needs to be thread safe.

Here's what I recommend:

  • add synchronized to all set* and init* methods . These methods are called infrequently so the synchronization penalty will be minimal
  • Make the restClient and executorService fields volatile
  • For getRestClient and getExecutorService we can minimize the synchronization by doing the double null check trick. Here is an example pattern on how to use it:
public static TwilioRestClient getRestClient() {
   if (restClient == null) {
      synchronized(Twilio.class) {
          if (restClient == null) {
              restClient = buildRestClient()
          }
      }
   }

  return restClient
}
@thinkingserious
Copy link
Contributor

Related to: #428

@thinkingserious thinkingserious added the status: duplicate duplicate issue label Nov 28, 2019
@childish-sambino childish-sambino added status: work in progress Twilio or the community is in the process of implementing type: community enhancement feature request not on Twilio's roadmap and removed status: duplicate duplicate issue labels Sep 23, 2020
@childish-sambino
Copy link
Contributor

Makes sense to me. Working on a fix ...

@childish-sambino childish-sambino added type: twilio enhancement feature request on Twilio's roadmap and removed type: community enhancement feature request not on Twilio's roadmap labels Sep 23, 2020
@childish-sambino childish-sambino removed the status: work in progress Twilio or the community is in the process of implementing label Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: twilio enhancement feature request on Twilio's roadmap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants