luarocks / luarocks-site

LuaRocks website and module host
http://luarocks.org
176 stars 36 forks source link

Error copying module to another user #163

Closed hishamhm closed 4 years ago

hishamhm commented 4 years ago

I got this error when doing the admin action of copying the luacheck entry from user mpeterv to user luarocks:

Error

...e/luarocks/.luarocks/share/lua/5.1/lapis/application.lua:401: ...e/luarocks/.luarocks/share/lua/5.1/lapis/application.lua:401: ...e/luarocks/.luarocks/share/lua/5.1/lapis/db/postgres.lua:95: INSERT INTO "versions" ("rockspec_fname", "version_name", "source_url", "created_at", "downloads", "development", "lua_version", "module_id", "updated_at", "rockspec_key", "rockspec_downloads") VALUES ('luacheck-0.21.2-1.rockspec', '0.21.2-1', 'git+https://github.com/mpeterv/luacheck.git', '2020-08-20 22:28:29', 205357, FALSE, 'lua >= 5.1, < 5.4', 568, '2020-08-20 22:28:29', '54/luacheck-0.21.2-1.rockspec', 57) RETURNING "id"
ERROR: duplicate key value violates unique constraint "versions_module_id_version_name_idx"
Key (module_id, version_name)=(568, 0.21.2-1) already exists.
stack traceback:
    [C]: in function 'error'
    ...e/luarocks/.luarocks/share/lua/5.1/lapis/db/postgres.lua:95: in function 'insert'
    ...ocks/.luarocks/share/lua/5.1/lapis/db/postgres/model.lua:193: in function 'create'
    ./models/modules.lua:241: in function 'copy_to_user'
    ./app.lua:344: in function <./app.lua:329>
stack traceback:
    [C]: in function 'error'
    ...e/luarocks/.luarocks/share/lua/5.1/lapis/application.lua:401: in function <...e/luarocks/.luarocks/share/lua/5.1/lapis/application.lua:394>

Traceback

stack traceback:
    [C]: in function 'error'
    ...e/luarocks/.luarocks/share/lua/5.1/lapis/application.lua:401: in function 'handler'
    ...e/luarocks/.luarocks/share/lua/5.1/lapis/application.lua:130: in function 'resolve'
    ...e/luarocks/.luarocks/share/lua/5.1/lapis/application.lua:167: in function <...e/luarocks/.luarocks/share/lua/5.1/lapis/application.lua:165>
    [C]: in function 'xpcall'
    ...e/luarocks/.luarocks/share/lua/5.1/lapis/application.lua:173: in function 'dispatch'
    /home/luarocks/.luarocks/share/lua/5.1/lapis/nginx.lua:230: in function 'serve'
    content_by_lua(nginx.conf.compiled:39):1: in function <content_by_lua(nginx.conf.compiled:39):1>
hishamhm commented 4 years ago

(It worked on a second try)

leafo commented 4 years ago

It it possible you double sent the request by clicking it twice by accident? That's the only think I can think of off the top of my head. There's probably a non-atomic check for existing then insert.

In any case, the request should be resilient to double inserts regardless.

hishamhm commented 4 years ago

Sounds harmless and enough of a corner case :)