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

_G write guard #676

Closed
webandbusiness opened this issue Aug 19, 2019 · 8 comments
Closed

_G write guard #676

webandbusiness opened this issue Aug 19, 2019 · 8 comments

Comments

@webandbusiness
Copy link

Hello, i am new in LAPIS+openresty 1.15
i am running a test application from openresty installation (not command line)
I have this issue since...., i tracked but no find any global variable declaration
Pls help!!

2019/08/19 08:25:28 [warn] 980#0: *80 [lua] _G write guard:12: writing a global lua variable ('socket') which may lead to race conditions between concurrent requests, so prefer the use of 'local' variables
stack traceback:
	[C]: at 0x7fca6bc70240
	[C]: in function 'require'
	/usr/local/share/lua/5.1/socket.lua:12: in main chunk
	[C]: in function 'require'
	/usr/local/share/lua/5.1/socket/url.lua:13: in main chunk
	[C]: in function 'require'
	/usr/local/share/lua/5.1/lapis/util.lua:1: in main chunk
	[C]: in function 'require'
	/usr/local/share/lua/5.1/lapis/cmd/util.lua:6: in main chunk
	[C]: in function 'require'
	/usr/local/share/lua/5.1/lapis/config.lua:120: in function 'get_env'
	/usr/local/share/lua/5.1/lapis/config.lua:127: in function 'get'
	/usr/local/share/lua/5.1/lapis/logging.lua:4: in main chunk
	[C]: in function 'require'
	/usr/local/share/lua/5.1/lapis/application.lua:1: in main chunk
	[C]: in function 'require'
	/usr/local/share/lua/5.1/lapis/init.lua:1: in main chunk
	[C]: in function 'require'
	/home/scrrim/app.lua:2: in main chunk, client: 129.0.80.212, server: www.mydomain.com, 
2019/08/19 08:25:28 [warn] 980#0: *80 [lua] _G write guard:12: writing a global lua variable ('lpeg') which may lead to race conditions between concurrent requests, so prefer the use of 'local' variables
stack traceback:
	[C]: at 0x7fca6b5f6420
	[C]: in function 'require'
	/usr/local/share/lua/5.1/lapis/util.lua:44: in main chunk
	[C]: in function 'require'
	/usr/local/share/lua/5.1/lapis/cmd/util.lua:6: in main chunk
	[C]: in function 'require'
	/usr/local/share/lua/5.1/lapis/config.lua:120: in function 'get_env'
	/usr/local/share/lua/5.1/lapis/config.lua:127: in function 'get'
	/usr/local/share/lua/5.1/lapis/logging.lua:4: in main chunk
	[C]: in function 'require'
	/usr/local/share/lua/5.1/lapis/application.lua:1: in main chunk
	[C]: in function 'require'
	/usr/local/share/lua/5.1/lapis/init.lua:1: in main chunk
	[C]: in function 'require'
	/home/scrrim/app.lua:2: in main chunk, client: 129.0.80.212, server: www.mydomain.com
@turbo
Copy link
Contributor

turbo commented Aug 19, 2019

I second this, it's pretty annoying. Though, this isn't from Lapis. As the stack trace tells you, the offenders are LPeg and LuaSocket. You can safely ignore this warning, it won't prevent you from running your code.

@ryanford
Copy link
Contributor

ryanford commented Aug 19, 2019

If you just want to silence the warning, you can require those rocks in an init_by_lua_block block in OpenResty (the nginx.conf). Maybe someday Lapis will ship with forked versions of it's dependencies that don't pollute the global namespace. I'm fairly certain the offenders won't fix it in the libraries as they're older/popular and it would potentially break tons of projects.

@leafo
Copy link
Owner

leafo commented Aug 20, 2019

you can get rid of the lpeg warning by upgrading to the latest vesrion iirc

regarding LuaSocket, it probably doesn't have to be a dependency that's loaded when running lapis inside of nginx

There are other things that we use that are more tricky to clean up though.

@cycomachead
Copy link
Contributor

Anyone know if it is possible to disable this? I find the logs distracting from what I'm actually looking for. (And though this seems like a good idea, luacheck covers my needs.)

Sorry, I know this is not a Lapis-specific question, but I looked around and the only other results are about disabling warnings in tests. I saw a mention of rawest, but I can't tell if it could have any adverse effects?

@turbo
Copy link
Contributor

turbo commented Nov 11, 2019

I find the logs distracting from what I'm actually looking for.

They should only occur once unless code cache is disabled. But even in tests, there is no reason to disable code cache (I'm using busted with resty to run tests). If you're running in nginx, ryan's advice is the easiest way to fix this (added benefit is that errors in required modules are found on server startup).

The only actual way to disable this is to recompile OpenResty from source and comment out the guard (or use an older version).

@DouFuJuShi
Copy link

I want to know where is the problem.
Whether it will pollute other libraries ?
And Whether affect the use of other libraries?
who can help me,I am new to this framework!
Thanks!!!

@sharpobject
Copy link
Contributor

The lpeg warning is still present in the latest version.

@leafo
Copy link
Owner

leafo commented Dec 11, 2020

I'm going to close this issue since there not much we can do, see this response from ryanford-dev:

If you just want to silence the warning, you can require those rocks in an init_by_lua_block block in OpenResty (the nginx.conf). Maybe someday Lapis will ship with forked versions of it's dependencies that don't pollute the global namespace. I'm fairly certain the offenders won't fix it in the libraries as they're older/popular and it would potentially break tons of projects.

It's safe to ignore these warnings, they will not cause any negative side-effects. Lapis requires these modules early on in the request. The race condition mentioned in the warning would be the result of having a module "double imported" where a newer one replaces over the older one. If this does happen, it will not cause any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants