[GRASS-dev] [GRASS GIS] #3631: Mapset remains locked after switch to it and exit

#3631: Mapset remains locked after switch to it and exit
-------------------------------------------------+-------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
     Type: defect | Status: assigned
Priority: normal | Milestone: 7.6.0
Component: Startup | Version: svn-trunk
Keywords: init, grass.py, lock, gislock, | CPU: Unspecified
  g.mapset |
Platform: Linux |
-------------------------------------------------+-------------------------
To reproduce:

1. Start in mapset A.
2. Switch to mapset B.
3. Exit.
4. Mapset B is still locked.

The problem is that `grass.py` tries to remove the lock from A, but that
was already removed. No warning or error is generated, because `grass.py`
''tries'' (`try_remove()`) and thus ignores any errors. This behavior
seems to be there at least since 7.0 (by looking at the code).

Influences:
* G7:g.mapset
* ''Settings > GRASS working environment > ...''
* workspace loading with "session" (#3575)

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3631&gt;
GRASS GIS <https://grass.osgeo.org>

#3631: Mapset remains locked after switch to it and exit
-------------------------+-------------------------------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: assigned
  Priority: normal | Milestone: 7.6.0
Component: Startup | Version: svn-trunk
Resolution: | Keywords: init, grass.py, lock, gislock,
       CPU: | g.mapset
  Unspecified | Platform: Linux
-------------------------+-------------------------------------------------
Changes (by wenzeslaus):

* Attachment "unlock_current_mapset.diff" added.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3631&gt;
GRASS GIS <https://grass.osgeo.org>

#3631: Mapset remains locked after switch to it and exit
-------------------------+-------------------------------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: assigned
  Priority: normal | Milestone: 7.6.0
Component: Startup | Version: svn-trunk
Resolution: | Keywords: init, grass.py, lock, gislock,
       CPU: | g.mapset
  Unspecified | Platform: Linux
-------------------------+-------------------------------------------------

Comment (by wenzeslaus):

The attached patch basically replaced removal of acquired lock stored in a
variable

{{{
if self.lockfile:
     try_remove(self.lockfile)
}}}

by removal based on the gisrc file.

{{{
def unlock_gisrc_mapset(gisrc, gisrcrc):
     settings = load_gisrc(gisrc, gisrcrc)
     lockfile = os.path.join(settings.full_mapset, ".gislock")
     try_remove(lockfile)
...
atexit.register(lambda: unlock_gisrc_mapset(gisrc, gisrcrc))
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3631#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3631: Mapset remains locked after switch to it and exit
-------------------------+-------------------------------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: assigned
  Priority: normal | Milestone: 7.6.0
Component: Startup | Version: svn-trunk
Resolution: | Keywords: init, grass.py, lock, gislock,
       CPU: | g.mapset
  Unspecified | Platform: Linux
-------------------------+-------------------------------------------------

Comment (by wenzeslaus):

See also #3635 for similar issue related to mapset tmp dir.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3631#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#3631: Mapset remains locked after switch to it and exit
-------------------------+-------------------------------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.6.0
Component: Startup | Version: svn-trunk
Resolution: fixed | Keywords: init, grass.py, lock, gislock,
       CPU: | g.mapset
  Unspecified | Platform: Linux
-------------------------+-------------------------------------------------
Changes (by wenzeslaus):

* status: assigned => closed
* resolution: => fixed

Comment:

In [changeset:"73335" 73335]:
{{{
#!CommitTicketReference repository="" revision="73335"
init: remove lock from the current mapset (fixes #3631)

Do not remove lock based on the path to the initially locked file,
but instead use the rc file point to by GISRC (assumed stable within this
proccess)
to find out the current mapset and remove lock file there.

Now a sequence start in mapset A, switch to B, exit removes all lock
files.
Before, only the A lock file was removed, specifically the lock file was
left
in the mapset exited from.
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3631#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>