Commit 3d69a025 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 18701c5a
...@@ -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
import httplib import httplib
import urllib import urllib
import json import json
...@@ -235,14 +234,8 @@ def getFacebookUserEntry(token): ...@@ -235,14 +234,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