I have an Flask app running on Google App Engine. I am trying to configure ereporter as per the instructions in this link.
I get the following error when I try to run my app using dev_appserver.py
Traceback (most recent call last):
File "/Users/xxx/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 82, in <module>
_run_file(__file__, globals())
File "/Users/xxx/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 78, in _run_file
execfile(_PATHS.script_file(script_name), globals_)
File "/Users/xxx/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 1001, in <module>
main()
File "/Users/xxx/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 994, in main
dev_server.start(options)
File "/Users/xxx/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 754, in start
options.config_paths)
File "/Users/xxx/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 632, in __init__
module_configuration = ModuleConfiguration(config_path)
File "/Users/xxx/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 97, in __init__
self._config_path)
File "/Users/xxx/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 316, in _parse_configuration
config, files = appinfo_includes.ParseAndReturnIncludePaths(f)
File "/Users/xxx/google-cloud-sdk/platform/google_appengine/google/appengine/api/appinfo_includes.py", line 81, in ParseAndReturnIncludePaths
appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
File "/Users/xxx/google-cloud-sdk/platform/google_appengine/google/appengine/api/appinfo.py", line 1873, in LoadSingleAppInfo
listener.Parse(app_info)
File "/Users/xxx/google-cloud-sdk/platform/google_appengine/google/appengine/api/yaml_listener.py", line 226, in Parse
self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
File "/Users/xxx/google-cloud-sdk/platform/google_appengine/google/appengine/api/yaml_listener.py", line 177, in _HandleEvents
raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError: threadsafe cannot be enabled with CGI handler: $PYTHON_LIB/google/appengine/ext/ereporter/report_generator.py
in "cfc-melbourne/app.yaml", line 51, column 1
app.yaml
# Handlers tell app engine how to route requests to your application.
handlers:
# This handler configures cron.yaml
- url: /_ereporter.*
script: $PYTHON_LIB/google/appengine/ext/ereporter/report_generator.py
login: admin
cron.yaml
cron:
- description: Daily exception report
url: /_ereporter?sender=xxx.xxx#gmail.com&delete=false&date=dd-mmm-yyyy # The sender must be an app admin.
schedule: every day 22:05
main.py
from google.appengine.ext import ereporter
ereporter.register_logger()
What am I missing ?
The problem is not flask, the problem is outdated documentation, because the configuration that is shown is for applications with threadsafe in false. for applications with threadsafe in true the configuration is below
- url: /_ereporter.*
script: google.appengine.ext.ereporter.report_generator.application
login: admin
this information is taken from https://groups.google.com/forum/#!topic/google-appengine/0v9KqB5Q8sQ
Related
I did a gcloud components update 2 days ago and started getting this error when i run dev_appserver.py
(venv) myusername#mymachine:~/projects/myproject$ dev_appserver.py ./ --host 0.0.0.0 --port 8002 --enable_console --env_var GCS_TOKEN=ya29........YJDQAnp772B0
INFO 2019-03-13 23:45:31,205 devappserver2.py:278] Skipping SDK update check.
INFO 2019-03-13 23:45:31,268 api_server.py:275] Starting API server at: http://localhost:64587
INFO 2019-03-13 23:45:31,319 dispatcher.py:256] Starting module "default" running at: http://0.0.0.0:8002
INFO 2019-03-13 23:45:31,325 admin_server.py:150] Starting admin server at: http://localhost:8000
/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/mtime_file_watcher.py:182: UserWarning: There are too many files in your application for changes in all of them to be monitored. You may have to restart the development server to see some changes to your files.
'There are too many files in your application for '
INFO 2019-03-13 23:45:35,237 instance.py:294] Instance PID: 29760
appengine_config
requests.__version__ 2.21.0
Appengine config done
4
ERROR 2019-03-13 23:45:35,986 wsgi.py:263]
Traceback (most recent call last):
File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/Users/myusername/projects/myproject/main.py", line 34, in <module>
from bp_includes.lib.error_handler import handle_error
File "/Users/myusername/projects/myproject/bp_includes/lib/error_handler.py", line 15, in <module>
from bp_includes.lib import jinja_bootstrap
File "/Users/myusername/projects/myproject/bp_includes/lib/jinja_bootstrap.py", line 7, in <module>
from src.handlers.utils import ordinal
File "/Users/myusername/projects/myproject/src/handlers/utils.py", line 14, in <module>
from lib.pytz.gae import pytz
File "/Users/myusername/projects/myproject/lib/pytz/__init__.py", line 29, in <module>
from pkg_resources import resource_stream
File "/Users/myusername/projects/myproject/lib/pkg_resources/__init__.py", line 1022, in <module>
class Environment(object):
File "/Users/myusername/projects/myproject/lib/pkg_resources/__init__.py", line 1025, in Environment
def __init__(self, search_path=None, platform=get_supported_platform(),
File "/Users/myusername/projects/myproject/lib/pkg_resources/__init__.py", line 263, in get_supported_platform
plat = get_build_platform()
File "/Users/myusername/projects/myproject/lib/pkg_resources/__init__.py", line 472, in get_build_platform
INFO 2019-03-13 23:45:36,002 module.py:861] default: "GET /_ah/warmup HTTP/1.1" 500 -
version = _macosx_vers()
File "/Users/myusername/projects/myproject/lib/pkg_resources/__init__.py", line 439, in _macosx_vers
version = platform.mac_ver()[0]
File "/Users/myusername/projects/myproject/venv/lib/python2.7/platform.py", line 764, in mac_ver
info = _mac_ver_xml()
File "/Users/myusername/projects/myproject/venv/lib/python2.7/platform.py", line 741, in _mac_ver_xml
pl = plistlib.readPlist(fn)
File "/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py", line 75, in readPlist
pathOrFile = open(pathOrFile)
File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime/stubs.py", line 284, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: '/System/Library/CoreServices/SystemVersion.plist'
I originally installed gcloud with brew cask install google-cloud-sdk in case that's relevant
It looks like the problem was introduced in gcloud 238.0.0 probably with gcloud app Python Extensions 1.9.84. You can downgrade gcloud to lower version with:
gcloud components update --version 237.0.0
I got it to work by doing the following in appengine_config.py, but I'm hoping that someone has a better solution
try:
from google.appengine.tools.devappserver2.python.runtime.stubs import FakeFile
FakeFile._allowed_dirs.update(['/System/Library/CoreServices/'])
except ImportError:
pass
you can delete the lib folder where you requirements are installed and reinstall it worked for me
pip install -t "lib" -r requirements.txt
I've been using GAE/P 1st gen for many years and am making the jump to my first GAE/P 2nd gen project.
I'm trying to run it locally like I did with dev_appserver.py for 1st gen apps, but the docs are very confusing in this respect.
I can run Flask on its own (python main.py) but static files don't work (since Flask knows nothing about app.yaml) and the datastore won't work either.
The GAE docs say that dev_appserver.py should work for 2nd gen (except on Windows but I'm on Mac) but when I run it, I get the error below.
This happens when I run dev_appserver.py with Python 2 or 3. I've also set CLOUDSDK_PYTHON to my Python 2 binary as instructed.
So how the heck can I run my GAE/P 2nd gen project locally in way that static files and the datastore work?!?
$ python ~/google-cloud-sdk/bin/dev_appserver.py --application=myapp --support_datastore_emulator=False ./app.yaml
INFO 2019-02-12 00:39:21,885 devappserver2.py:278] Skipping SDK update check.
INFO 2019-02-12 00:39:23,128 api_server.py:275] Starting API server at: http://localhost:51187
INFO 2019-02-12 00:39:23,139 instance_factory.py:71] Detected Python 3.6.5
INFO 2019-02-12 00:39:24,459 instance_factory.py:205] Using pip to install dependency libraries; pip stdout is redirected to /var/folders/yd/xr84fg0946l72fp_cc6j9l540000gr/T/tmpj3SEUZ
INFO 2019-02-12 00:39:24,459 instance_factory.py:211] Running /var/folders/yd/xr84fg0946l72fp_cc6j9l540000gr/T/tmpLtysT3/bin/pip install --upgrade pip
INFO 2019-02-12 00:39:24,469 stub_util.py:357] Applying all pending transactions and saving the datastore
INFO 2019-02-12 00:39:24,469 stub_util.py:360] Saving search indexes
Traceback (most recent call last):
File "/.../google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 96, in <module>
_run_file(__file__, globals())
File "/.../google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 90, in _run_file
execfile(_PATHS.script_file(script_name), globals_)
File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 600, in <module>
main()
File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 588, in main
dev_server.start(options)
File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 360, in start
options.api_host, apiserver.port, wsgi_request_info_)
File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/dispatcher.py", line 248, in start
ssl_port)
File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/dispatcher.py", line 384, in _create_module
ssl_port=ssl_port)
File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py", line 1309, in __init__
super(AutoScalingModule, self).__init__(**kwargs)
File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py", line 598, in __init__
self._module_configuration)
File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py", line 231, in _create_instance_factory
module_configuration=module_configuration)
File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/instance_factory.py", line 98, in __init__
self._SetupVirtualenvFromConfiguration()
File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/instance_factory.py", line 143, in _SetupVirtualenvFromConfiguration
self._venv_dir, requirements_file.name)
File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/instance_factory.py", line 228, in _SetupVirtualenv
cls._RunPipInstall(venv_dir, requirements_file_name)
File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/instance_factory.py", line 212, in _RunPipInstall
pip_proc = subprocess.Popen(pip_cmd, stdout=pip_out)
File "/usr/local/Cellar/python#2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 394, in __init__
errread, errwrite)
File "/usr/local/Cellar/python#2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1047, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
After a good night's sleep, I was able to figure out the problem...
I was running dev_appserver.py from within my virtual environment. For some reason, this prevented dev_appserver.py from being able to find pip (needed to install the packages in my requirements.txt).
Exiting my virtual environment before running dev_appserver.py fixed the problem.
I am unable to deploy my App Engine Flex Python project with split health checks.
I have enabled health checks:
$ gcloud beta app describe
...
featureSettings:
splitHealthChecks: true
Using the docs as a model, my app.yaml has:
readiness_check:
path: '/health_check'
check_interval_sec: 5
timeout_sec: 4
failure_threshold: 2
success_threshold: 2
app_start_timeout_sec: 600
liveness_check:
path: '/health_check'
check_interval_sec: 30
timeout_sec: 4
failure_threshold: 2
success_threshold: 2
But when I deploy, it fails due to the following error:
File "/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
worker.init_process()
File "/env/local/lib/python2.7/site-packages/gunicorn/workers/gthread.py", line 109, in init_process
super(ThreadWorker, self).init_process()
File "/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
self.load_wsgi()
File "/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
self.wsgi = self.app.wsgi()
File "/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/env/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
__import__(module)
File "/env/local/lib/python2.7/site-packages/vmruntime/wsgi.py", line 48, in <module>
wsgi_config.get_module_config_filename())
File "/env/local/lib/python2.7/site-packages/vmruntime/wsgi_config.py", line 48, in get_module_config
return appinfo_includes.Parse(f)
File "/env/local/lib/python2.7/site-packages/google/appengine/api/appinfo_includes.py", line 57, in Parse
appyaml, _ = ParseAndReturnIncludePaths(appinfo_file, open_fn)
File "/env/local/lib/python2.7/site-packages/google/appengine/api/appinfo_includes.py", line 82, in ParseAndReturnIncludePaths
appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
File "/env/local/lib/python2.7/site-packages/google/appengine/api/appinfo.py", line 2417, in LoadSingleAppInfo
listener.Parse(app_info)
File "/env/local/lib/python2.7/site-packages/google/appengine/api/yaml_listener.py", line 227, in Parse
self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
File "/env/local/lib/python2.7/site-packages/google/appengine/api/yaml_listener.py", line 178, in _HandleEvents
raise yaml_errors.EventError(e, event_object)
EventError: Unexpected attribute 'failure_threshold' for object of type ReadinessCheck.
I'm following the documentation so I'm not sure why it would be triggering an error here.
The only thing I can imagine is that my 'site-packages' is perhaps out of date? I don't believe my Docker should install any google/appengine/ libraries, but I'm at a loss for what I could be doing wrong.
So seems the above failure scenario is caused by the gcr.io/google_appengine/python-compat-multicore docker image being out of date.
The github is up to date with the latest python files, but the associated Docker image was never rebuilt.
I have fixed this particular error by checking out the github and rebuilding the docker image myself, and pointing my appengine flex stuff at my own parent-built-image.
(I now have a separate problem, with split healthchecks being sent to the default paths, and it not letting me override the paths. I have filed that as bug in the Google cloud issue tracker. But at least the above question is now solved for me)
I have an endpoint that receives a batch of 10k-20k records. It returns a job id and launches deferred tasks to process these in parallel. It seems that sometimes one of the new instances will grab a few of the tasks, but not actually process them. It seems that the instance died instantly.
Eventually those tasks hit their 10 minute timeout and are launched again.
If I find one of these tasks and filter by the id of instance that was running it, this is what I see in Google Logs Viewer:
Most of the log entries just have this message "Process terminated because the request deadline was exceeded during a loading request." The message's timestamp is 10 minutes after the timestamp of the request.
One has this stack trace:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 351, in __getattr__
self._update_configs()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 283, in _update_configs
self._lock.acquire()
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/threading.py", line 170, in acquire
self.__count = self.__count + 1
DeadlineExceededError: The overall deadline for responding to the HTTP request was exceeded.
Another has this one:
(/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py:252)
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 351, in __getattr__
self._update_configs()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 287, in _update_configs
self._registry.initialize()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 160, in initialize
import_func(self._modname)
File "/base/data/home/apps/s~myappid/dev.403063962077465992/appengine_config.py", line 12, in <module>
vendor.add('lib')
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/vendor/__init__.py", line 40, in add
elif os.path.isdir(path):
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/genericpath.py", line 52, in isdir
return stat.S_ISDIR(st.st_mode)
DeadlineExceededError: The overall deadline for responding to the HTTP request was exceeded.
Another has this one:
(/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py:252)
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 351, in __getattr__
self._update_configs()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 287, in _update_configs
self._registry.initialize()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 160, in initialize
import_func(self._modname)
File "/base/data/home/apps/s~myappid/dev.403063962077465992/appengine_config.py", line 14, in <module>
from lib import requests
File "/base/data/home/apps/s~myappid/dev.403063962077465992/lib/requests/__init__.py", line 52, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/base/data/home/apps/s~myappid/dev.403063962077465992/lib/requests/packages/__init__.py", line 27, in <module>
from . import urllib3
File "/base/data/home/apps/s~myappid/dev.403063962077465992/lib/requests/packages/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/base/data/home/apps/s~myappid/dev.403063962077465992/lib/requests/packages/urllib3/connectionpool.py", line 29, in <module>
from .connection import (
File "/base/data/home/apps/s~myappid/dev.403063962077465992/lib/requests/packages/urllib3/connection.py", line 39, in <module>
from .util.ssl_ import (
File "/base/data/home/apps/s~myappid/dev.403063962077465992/lib/requests/packages/urllib3/util/__init__.py", line 3, in <module>
from .connection import is_connection_dropped
File "/base/data/home/apps/s~myappid/dev.403063962077465992/lib/requests/packages/urllib3/util/connection.py", line 145, in <module>
HAS_IPV6 = _has_ipv6('::1')
File "/base/data/home/apps/s~myappid/dev.403063962077465992/lib/requests/packages/urllib3/util/connection.py", line 135, in _has_ipv6
sock.bind((host, 0))
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/socket.py", line 227, in meth
return getattr(self._sock,name)(*args)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/remote_socket/_remote_socket.py", line 663, in bind
self._CreateSocket(bind_address=address)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/remote_socket/_remote_socket.py", line 609, in _CreateSocket
'remote_socket', 'CreateSocket', request, reply)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 95, in MakeSyncCall
return stubmap.MakeSyncCall(service, call, request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 329, in MakeSyncCall
rpc.CheckSuccess()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_rpc.py", line 133, in CheckSuccess
elif self.exception:
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_rpc.py", line 136, in exception
#property
DeadlineExceededError: The overall deadline for responding to the HTTP request was exceeded.
This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.
The main issue is that I need to finish processing the batch within 5-10 minutes.
Each record in the batch should only take a minute to process, so a solution would be modifying the 10 minute timeout, but Google support said that isn't possible.
I tried implementing warmpup requests to try to address the loading requests, but that seemed to have no impact.
My previous answer worked for a glorious 24 hrs before the issue appeared again. It felt like the issue became less frequent after upgrading python requests from 2.12.3 to 2.18.2, but it's hard to say.
Regardless the solution that did ultimately work was editing the source code of urllib3 (it has been 5 days now, and the issue has not happened).
In the file urllib3/util/connection.py, hardcode _has_ipv6(host) to always return false (it always does in app engine anyway)
def _has_ipv6(host):
""" Returns True if the system can bind an IPv6 address. """
+ return False
sock = None
has_ipv6 = False
if socket.has_ipv6:
# has_ipv6 returns true if cPython was compiled with IPv6 support.
# It does not tell us if the system has IPv6 support enabled. To
# determine that we must bind to an IPv6 address.
# https://github.com/shazow/urllib3/pull/611
# https://bugs.python.org/issue658327
try:
sock = socket.socket(socket.AF_INET6)
sock.bind((host, 0))
has_ipv6 = True
except Exception:
pass
if sock:
sock.close()
return has_ipv6
HAS_IPV6 = _has_ipv6('::1')
I believe the problem is ultimately the call to sock.bind((host, 0)) which hangs and according to google's docs https://cloud.google.com/appengine/docs/standard/python/sockets/
You cannot bind to specific IP addresses or ports.
I was able to create an isolated GAE sample project that show cases the issue. Install these third party libraries pip install requests requests_toolbelt -t lib to a folder called lib and create these files:
app.yaml:
application: #your project id here
version: dev
runtime: python27
api_version: 1
threadsafe: true
inbound_services:
- warmup
automatic_scaling:
min_idle_instances: 0
max_concurrent_requests: 8 # default value
env_variables:
GAE_USE_SOCKETS_HTTPLIB : 'true'
builtins:
- appstats: on #/_ah/stats/
- remote_api: on #/_ah/remote_api/
- deferred: on
handlers:
- url: /.*
script: main.app
libraries:
- name: jinja2
version: "2.6"
- name: webapp2
version: "2.5.2"
- name: markupsafe
version: "0.15"
- name: ssl
version: "2.7.11"
- name: pycrypto
version: "2.6"
- name: lxml
version: latest
main.py:
import webapp2
import requests
import time
from google.appengine.api.taskqueue import taskqueue
from google.appengine.api import app_identity
from google.appengine.ext import deferred, ndb
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('''<form method="POST"><input type="submit" value="Launch"></form>''')
def post(self):
queue = taskqueue.Queue()
futures = [queue.add_async(taskqueue.Task(url="/task")) for _ in xrange(0, 2000)]
ndb.Future.wait_all(futures)
print 'launched'
self.get()
class TaskHandler(webapp2.RequestHandler):
def post(self):
try:
r = requests.post("https://"+app_identity.get_application_id()+".appspot.com/post")
print r.text
except Exception as e:
print str(e)
class RequestFromTaskHandler(webapp2.RequestHandler):
def post(self):
time.sleep(2)
self.response.write('responded')
app = webapp2.WSGIApplication([
('/', MainHandler),
('/_ah/warmup', MainHandler),
('/task', TaskHandler),
('/post', RequestFromTaskHandler),
], debug=True)
appengine_config.py:
import os
from google.appengine.ext import vendor
vendor.add('lib')
import requests
from requests_toolbelt.adapters import appengine as requests_toolbelt_appengine
# Use the App Engine Requests adapter. This makes sure that Requests uses
# URLFetch.
requests_toolbelt_appengine.monkeypatch()
queue.yaml:
queue:
- name: default
rate: 100/s
bucket_size: 500
max_concurrent_requests: 1000
Essentially a POST to MainHandler will launch 2000 deferred tasks that try to create an outbound request (to itself).
Go here to monitor the batch: https://console.cloud.google.com/appengine/taskqueues
You should see most of the tasks finish up quickly except for a few which will continue to say that they are running for 10 minutes.
After they finish they will then appear in logs viewer.
For some reason if I don't disable & then re-enable the project, the issue only happens on the first batch of 2000.
After you have been able to replicate the issue. If you make the change to urllib3, the issue shouldn't happen anymore.
This was for urllib3 version 1.22
it seems to be that you are running an Automatic scaling instance which has a time limit of ten minutes for queues. You can try to switch to a different instance type like Manual scaling. Please see the following link: https://cloud.google.com/appengine/docs/standard/python/an-overview-of-app-engine
When I follow Google-Developers' tutorial for creating a simple application in Go using App Engine SDK for Go, while running the command
goapp serve
I receive the following error:
Traceback (most recent call last):
File "/home/kamal/go_appengine/dev_appserver.py", line 82, in <module>
_run_file(__file__, globals())
File "/home/kamal/go_appengine/dev_appserver.py", line 78, in _run_file
execfile(_PATHS.script_file(script_name), globals_)
File "/home/kamal/go_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 1001, in <module>
main()
File "/home/kamal/go_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 994, in main
dev_server.start(options)
File "/home/kamal/go_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 754, in start
options.config_paths)
File "/home/kamal/go_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 632, in __init__
module_configuration = ModuleConfiguration(config_path)
File "/home/kamal/go_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 97, in __init__
self._config_path)
File "/home/kamal/go_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 316, in _parse_configuration
config, files = appinfo_includes.ParseAndReturnIncludePaths(f)
File "/home/kamal/go_appengine/google/appengine/api/appinfo_includes.py", line 81, in ParseAndReturnIncludePaths
appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
File "/home/kamal/go_appengine/google/appengine/api/appinfo.py", line 1873, in LoadSingleAppInfo
listener.Parse(app_info)
File "/home/kamal/go_appengine/google/appengine/api/yaml_listener.py", line 226, in Parse
self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
File "/home/kamal/go_appengine/google/appengine/api/yaml_listener.py", line 177, in _HandleEvents
raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError: Unknown url handler type.
URLMap
auth_fail_action=redirect
static_dir=None
secure=default
http_headers=None
url=/.*
static_files=None
expiration=None
upload=None
api_endpoint=None
script=None
application_readable=None
position=None
login=optional
mime_type=None
require_matching_file=None
in "myapp/app.yaml", line 8, column 1
error while running dev_appserver.py: exit status 1
I don't know how to debug it. Just a hint would be sufficient.
Also, can it be because I have no web server installed? Do I have to install Apache or Nginx for goapp serve or go handles the server stuff itself?
The problem was indentation of script in handlers in .yaml file.
I initially did it like this:
handlers:
- url: /.*
script: _go_app
While it should be:
handlers:
- url: /.*
script: _go_app
It works now!