[keycloak-user] admin-client hang

Marek Posolda mposolda at redhat.com
Wed Apr 18 14:03:18 EDT 2018


On 18/04/18 18:19, Nhut Thai Le wrote:
> I changed my code to close the response and i don't get the hang 
> anymore. At the moment, I always get the response status code and 
> close the response like this:
>
> Response resp = 
> admin.realm("test").clients().get("clientUuid").authorization().policies().client().create(policyRep);
> int code = resp.getStatus();
> resp.close();
>
> however fi i use a method that return a response but don't use it, 
> would it automatically close? For example:
>
> admin.realm("test").clients().get("clientUuid").authorization().policies().client().create(policyRep);
No, it won't close automatically. Which is quite error-prone and danger. 
IMO our admin client should never be done in a way to return those 
Response objects.

My personal opinion would be to never return those responses, but rather 
return the created object including his ID as a result of the "create" 
methods. That has the advantages that:
- caller will know ID easily (currently ID is available as a last part 
of the "Location" header of the response and it's not so trivial to 
retrieve it).
- Responses will be closed automatically
- Better API - In case of error, the exception will be thrown instead of 
the caller required to parse Response body, status etc. Which I 
personally like much more.

The disadvantages are:
- The create method will automatically return created objects, so 
responses might be a bit bigger. But that's very minor disadvantage
- It needs to be done :) . And backwards compatibility

Marek

>
> Thai
>
>
>
> On Wed, Apr 18, 2018 at 9:35 AM, Nhut Thai Le <ntle at castortech.com 
> <mailto:ntle at castortech.com>> wrote:
>
>     Thank you for the hint. I use the builder with 80 connections pool
>     and I still have the hang problem. I didn't know that I have to
>     close the response. I though the whole point of using pool is that
>     i dont have to worry about the life cycle of the connection
>     anymore. Anyway, will try what you suggested.
>
>     Thai
>
>
>
>     On Wed, Apr 18, 2018 at 3:21 AM, Marek Posolda
>     <mposolda at redhat.com <mailto:mposolda at redhat.com>> wrote:
>
>         On 17/04/18 21:28, Nhut Thai Le wrote:
>
>             Hello,
>
>             I'm writing a script to automate our realm setup using
>             keycloak
>             admin-client. I use the same client for multiple calls and
>             at some point,
>             my script hang. Is there any issue with using the same
>             client for multiple
>             calls?
>
>         It's not an issue, but make sure that:
>         - You use connection pooling. By default, it's 10 connections.
>         See source of classes Keycloak and KeycloakBuilder
>         - Make sure you close responses. Especially for the "create"
>         methods, which returns Response objects, you need to
>         explicitly close them. For the methods, which returns void or
>         JSON objects, you don't need to do anything
>
>         If needed, see our testsuite for more inspirations. It's using
>         adminClient in almost all the tests.
>
>             Is each public method of the admin-client asynchronous? If
>             yes, how
>             do I chain calls like: create realm-> create client ->
>             create resource ->
>             create permissions -> create policy,...
>
>         No, calls are synchronous and chaining shouldn't be an issue.
>
>         Marek
>
>
>             Thai
>             _______________________________________________
>             keycloak-user mailing list
>             keycloak-user at lists.jboss.org
>             <mailto:keycloak-user at lists.jboss.org>
>             https://lists.jboss.org/mailman/listinfo/keycloak-user
>             <https://lists.jboss.org/mailman/listinfo/keycloak-user>
>
>
>
>
>
>
>     -- 
>     Castor Technologies Inc
>     460 rue St-Catherine St Ouest, Suite 613
>     Montréal, Québec H3B-1A7
>     (514) 360-7208 o
>     (514) 798-2044 f
>     ntle at castortech.com <mailto:ntle at castortech.com>
>     www.castortech.com <http://www.castortech.com>
>
>     CONFIDENTIALITY NOTICE: The information contained in this e-mail
>     is confidential and may be proprietary information intended only
>     for the use of the individual or entity to whom it is addressed.
>     If the reader of this message is not the intended recipient, you
>     are hereby notified that any viewing, dissemination, distribution,
>     disclosure, copy or use of the information contained in this
>     e-mail message is strictly prohibited. If you have received and/or
>     are viewing this e-mail in error, please immediately notify the
>     sender by reply e-mail, and delete it from your system without
>     reading, forwarding, copying or saving in any manner. Thank you.
>     AVIS DE CONFIDENTIALITE: L’information contenue dans ce message
>     est confidentiel, peut être protégé par le secret professionnel et
>     est réservé à l'usage exclusif du destinataire. Toute autre
>     personne est par les présentes avisée qu'il lui est strictement
>     interdit de diffuser, distribuer ou reproduire ce message. Si vous
>     avez reçu cette communication par erreur, veuillez la détruire
>     immédiatement et en aviser l'expéditeur. Merci.
>
>
>
>
> -- 
> Castor Technologies Inc
> 460 rue St-Catherine St Ouest, Suite 613
> Montréal, Québec H3B-1A7
> (514) 360-7208 o
> (514) 798-2044 f
> ntle at castortech.com <mailto:ntle at castortech.com>
> www.castortech.com <http://www.castortech.com>
>
> CONFIDENTIALITY NOTICE: The information contained in this e-mail is 
> confidential and may be proprietary information intended only for the 
> use of the individual or entity to whom it is addressed. If the reader 
> of this message is not the intended recipient, you are hereby notified 
> that any viewing, dissemination, distribution, disclosure, copy or use 
> of the information contained in this e-mail message is strictly 
> prohibited. If you have received and/or are viewing this e-mail in 
> error, please immediately notify the sender by reply e-mail, and 
> delete it from your system without reading, forwarding, copying or 
> saving in any manner. Thank you.
> AVIS DE CONFIDENTIALITE: L’information contenue dans ce message est 
> confidentiel, peut être protégé par le secret professionnel et est 
> réservé à l'usage exclusif du destinataire. Toute autre personne est 
> par les présentes avisée qu'il lui est strictement interdit de 
> diffuser, distribuer ou reproduire ce message. Si vous avez reçu cette 
> communication par erreur, veuillez la détruire immédiatement et en 
> aviser l'expéditeur. Merci.




More information about the keycloak-user mailing list