Skip to content

Loopback API returns wrong responses on simultaneous requests  #2485

Closed

Description

@ReLrO

Hey guys,

I've been experiencing a very odd behavior with loopback when querying it with simultaneous requests. sometimes I am getting the expected responses, but on other times I am getting the wrong responses.

Here is what I am doing:

On the client side I am sending 2 ajax GET requests to the following url's:

url: `http://localhost:8000/api/customers/${userId}/groups/?type=1`
url: `http://localhost:8000/api/customers/${userId}/groups/?type=2`

the Customer and Group models have a many to many relationship through a CustomerGroup table and in CustomerGroup I have another column called 'type'. I placed an observer on customer-group.js which observes 'access'. When it enters the observer I am grabbing the type from the url by fetching it from ctx.active.http.req.query.type and then I am assigning it to context.query.where.type (ctx equals to loopback.getCurrentContext(); and context is the function's parameter).

This seems to always work fine when I call it with postman, but when I am calling it from the client side with ajax, the responses get mixed up between the two requests. For example, I am getting part of the response that I should have received for type=2 in type=1 and vice versa, and sometimes I am only getting partial responses - Not all the record I should have received in the result are fetched in the response.

Can anyone help me figure out what's going on here?

Activity

  1. loay commented on Jul 14, 2016

    @loay
    Contributor

    Hi @ReLrO
    As in the comment above by @alexDA14 , that's the current status of getCurrentContext()
    If you are looking for another alternative or another way to fix it, please provide a sample repo so we can debug it. As you said, the proper responses are intermittent, so I will have to investigate using a sample repo. Thanks.

  2. bajtos commented on Jan 9, 2017

    @bajtos
    Member

    I am closing this issue as there are not clear instructions how to reproduce it, plus we have deprecated getCurrentContext APIs. If the problem is still relevant, then please open a new issue in https://github.com/strongloop/loopback-context/issues and create a sample app reproducing the problem (see http://loopback.io/doc/en/contrib/Reporting-issues.html#bug-report).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions