[Geoserver-devel] [GEOS-8603] StackOverflowError caused by Secure Catalog decorators

Hello GeoServer developers.

I’ve been trying to track down a pesky bug that is causing some layers in GeoServer to eventually throw a StackOverflowError during GetCapabilities and GetMaps calls to the layer. If left unaddressed, even things like trying to navigate to the Layer list page in GeoServer or the Layer Preview page would also through StackOverflowErrors.

I’ve captured some of the details in this ticket: https://osgeo-org.atlassian.net/browse/GEOS-8603

With a lot of help from Gabriel Roldan, we dug into the issue and found the main symptom to be that, over time, the DataStoreInfo object in the Catalog would keep getting wrapped in extra layers of SecuredDataStoreInfo and ModificationProxy instances. Debugging and catching the error showed that the issue stemmed from REST calls that modified FeatureTypeInfo elements in the Catalog.

Further debugging led us to SecuredFeatureTypeInfo where the getStore() is overridden to return a wrapped SecuredDataStoreInfo instance, but setStore(StoreInfo) is not overridden to ensure that the StoreInfo is unwrapped before setting the value on the delegate. This seems to present a memory leak of sorts, as a PUT of a FeatureTypeInfo, in this environment, seems to use OwsUtils.copy() to invoke the decorated getter getStore() toretrieve a decorated DataStoreInfo that is then set on the target FeatureTypeInfo. If this process is repeated over and over, it will continually wrap the FeatureTypeInfo’s DataStoreInfo with another decorated layer.

When the object is eventually need to provide a response to a GetCapabilities or GetMap request, ResourcePool.getDataStore(DataStoreInfo) is called and the first thing that happens there is deep cloning of the DataStoreInfo. If the FeatureTypeInfo associated with the DataStore has been modified enough times, cloning the object will recursively dive into the nested decorator wrappers and eventually, a StackOverflowError happens trying to serialize or deserialize the object.

Gabriel and I have tested out a small patch to at least prevent the nested wrapping of DataStoreInfo by providing a SecuredFeatureTypeInfo.setStore(StoreInfo) override that unwraps the StoreInfo provided if it is secured. In the limited testing of repeated PUTs of the FeatureTypeInfo, it seems to prevent the repeated nesting of the catalog info and does not cause a StackOverflowError.

I’ve put the changes into a PR here: https://github.com/geoserver/geoserver/pull/2771

and welcome a discussion and feedback.

···

Erik Merkle
Software Engineer | Boundless

On Tue, Feb 27, 2018 at 6:14 PM, Erik Merkle <emerkle@anonymised.com>
wrote:

I've put the changes into a PR here: https://github.com/geoserver/
geoserver/pull/2771
and welcome a discussion and feedback.

Hey Erik,
I gave the pull request a very quick glance and have one worry about the
unwrap call.
One (and only one) modification proxy must still remain in the wrapping
chain of the object
returned by the catalog, otherwise any change made to the object via the UI
will
immediately reflect in the catalog, even if someone does not press "save".
Is that still the case?

Cheers
Andrea

==
GeoServer Professional Services from the experts! Visit http://goo.gl/it488V
for more information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via di Montramito 3/A
55054 Massarosa (LU)
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it

AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o
nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il
loro utilizzo è consentito esclusivamente al destinatario del messaggio,
per le finalità indicate nel messaggio stesso. Qualora riceviate questo
messaggio senza esserne il destinatario, Vi preghiamo cortesemente di
darcene notizia via e-mail e di procedere alla distruzione del messaggio
stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso,
divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od
utilizzarlo per finalità diverse, costituisce comportamento contrario ai
principi dettati dal D.Lgs. 196/2003.

The information in this message and/or attachments, is intended solely for
the attention and use of the named addressee(s) and may be confidential or
proprietary in nature or covered by the provisions of privacy act
(Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection
Code).Any use not in accord with its purpose, any disclosure, reproduction,
copying, distribution, or either dissemination, either whole or partial, is
strictly forbidden except previous formal approval of the named
addressee(s). If you are not the intended recipient, please contact
immediately the sender by telephone, fax or e-mail and delete the
information in this message that has been received in error. The sender
does not give any warranty or accept liability as the content, accuracy or
completeness of sent messages and accepts no responsibility for changes
made after they were sent or for other risks which arise as a result of
e-mail transmission, viruses, etc.