Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queries hang in WebApi actions #22

Open
tamasvajk opened this issue Apr 5, 2016 · 5 comments
Open

Queries hang in WebApi actions #22

tamasvajk opened this issue Apr 5, 2016 · 5 comments
Labels

Comments

@tamasvajk
Copy link
Owner

Issue raised through NuGet e-mail.

I tried the following, and it works without problem:

public async Task<IEnumerable<string>> Get()
{
    var scanner = new Scanner(ConfigurationManager.AppSettings["apiKey"]);
    var fromPlace = (await scanner.QueryLocation("London")).First();
    var toPlace = (await scanner.QueryLocation("New York")).First();

    //Query flights
    var itineraries = await scanner.QueryFlight(
      new FlightQuerySettings(
        new FlightRequestSettings(
          fromPlace, toPlace,
          new LocalDate(2016, 06, 19), new LocalDate(2016, 06, 25)),
        new FlightResponseSettings(SortType.Price, SortOrder.Ascending)));

    var itinerary = itineraries.First();
    var estimatedPrice = itinerary.PricingOptions.Min(option => option.Price);

    //Query booking
    var booking = await scanner.QueryBooking(itinerary);
    var actualPrice = booking.BookingOptions
      .Select(option => option.BookingItems.Sum(item => item.Price))
      .Min();

    ...
}
@tamasvajk tamasvajk added the bug label Apr 5, 2016
@KirillShlenskiy
Copy link

KirillShlenskiy commented Jun 21, 2016

I obviously haven't seen the original e-mail, but this sounds like a deadlock caused by the client code blocking on one of the Tasks returned by a SkyScanner API method. This will occur (at least partly) because you're not using ConfigureAwait(false) on any of the Tasks awaited inside the current code base.

As an illustration, new Scanner(ConfigurationManager.AppSettings["apiKey"]).QueryFlight(flightSettings).Result will deadlock in Web API.

You won't reproduce this in a console or test project as they run with SynchronizationContext.Current == null and so all awaitable objects will have ConfigureAwait(false) semantics by default.

@tamasvajk
Copy link
Owner Author

Thanks @KirillShlenskiy. I tried to repro this in a WebAPI project and couldn't. But the .ConfigureAwait(false) makes sense.

@filippobottega
Copy link

Hello,
this code in a console application hangs at line Dim itineraries = queryFlightTask.Result

Best regards,
Filippo Bottega.

Imports NodaTime
Imports SkyScanner.Services
Imports SkyScanner.Settings

Module Module1

  Sub Main()
    Dim scanner = New Scanner("APIKey"))
    Dim queryLocationTask = scanner.QueryLocation("Venezia")
    queryLocationTask.ConfigureAwait(False)
    Dim fromPlace = (queryLocationTask.Result).First()
    Console.WriteLine($"{NameOf(fromPlace)}: {fromPlace.ToString}")
    queryLocationTask = scanner.QueryLocation("London")
    queryLocationTask.ConfigureAwait(False)
    Dim toPlace = (queryLocationTask.Result).First()
    Console.WriteLine($"{NameOf(toPlace)}: {toPlace.ToString}")

    'Query flights
    Dim queryFlightTask = scanner.QueryFlight(New FlightQuerySettings(New FlightRequestSettings(fromPlace, toPlace, New LocalDate(2016, 12, 23), New LocalDate(2016, 12, 31)), New FlightResponseSettings(SortType.Price, SortOrder.Ascending)))
    queryFlightTask.ConfigureAwait(False)
    **Dim itineraries = queryFlightTask.Result**

    Dim itinerary = itineraries.First()
    Console.WriteLine($"{NameOf(itinerary)}: {itinerary.ToString}")

    Dim estimatedPrice = itinerary.PricingOptions.Min(Function([option]) [option].Price)
    Console.WriteLine($"{NameOf(estimatedPrice)}: {estimatedPrice.ToString}")

    'Query booking
    Dim queryBookingTask = scanner.QueryBooking(itinerary)
    queryBookingTask.ConfigureAwait(False)
    Dim booking = queryBookingTask.Result
    Dim actualPrice = booking.BookingOptions.[Select](Function([option]) [option].BookingItems.Sum(Function(item) item.Price)).Min()
    Console.WriteLine($"{NameOf(actualPrice)}: {actualPrice.ToString}")
  End Sub

End Module

@filippobottega
Copy link

I found this:
Which services can I access and what are the rate limits?

Please note access to our Hotels API and Flights Live Pricing service are currently suspended. Apologies, but we are unable to give a date for these services to be re-launched, but please do check back regularly for updates.

If I use my API key I get:

{
  "status": 429,
  "statusText": "OK",
  "debugInformation": {
    "ValidationErrors": [
      {
        "Message": "Rate limit has been exceeded: 0 PerMinute for PricingSession"
      }
    ]
  }
}

Maybe this is the reason of the application's hang ...

Filippo.

@tamasvajk
Copy link
Owner Author

Thanks for investigating this further. You're right, I haven't tested this scenario. It's a shame that SkyScanner has shut down the service. I hope it's only temporary. I'll try to contact them to get more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants