Commit bcce6fb1 authored by Jérome Perrin's avatar Jérome Perrin

ERP5ExternalOauth2ExtractionPlugin: use facebook.GraphAPI timeout argument

Instead of temporarily changing the global timeout, which can impact
other parts of the system and which is not free from race conditions (
another thread might have changed the timeout when socket.getdefaulttimeout()
is called and then we restore a wrong default timeout).
parent 19645b96
...@@ -39,7 +39,6 @@ from AccessControl.SecurityManagement import getSecurityManager, \ ...@@ -39,7 +39,6 @@ from AccessControl.SecurityManagement import getSecurityManager, \
setSecurityManager, newSecurityManager setSecurityManager, newSecurityManager
from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE
import time import time
import socket
from six.moves import urllib from six.moves import urllib
import json import json
from zLOG import LOG, ERROR, INFO from zLOG import LOG, ERROR, INFO
...@@ -234,14 +233,8 @@ def getFacebookUserEntry(token): ...@@ -234,14 +233,8 @@ def getFacebookUserEntry(token):
'No facebook module, install facebook-sdk package. ' 'No facebook module, install facebook-sdk package. '
'Authentication disabled.') 'Authentication disabled.')
return None return None
timeout = socket.getdefaulttimeout()
args = {'fields' : 'id,name,email', } args = {'fields' : 'id,name,email', }
try: facebook_entry = facebook.GraphAPI(token, timeout=5).get_object("me", **args)
# require really fast interaction
socket.setdefaulttimeout(5)
facebook_entry = facebook.GraphAPI(token).get_object("me", **args)
finally:
socket.setdefaulttimeout(timeout)
user_entry = {} user_entry = {}
if facebook_entry is not None: if facebook_entry is not None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment