Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Plugin HTTP handler or Lambda not getting called, after triggering after_save with async=True #347

Closed
Steven-Chan opened this issue Apr 11, 2017 · 4 comments
Assignees
Labels

Comments

@Steven-Chan
Copy link
Contributor

Steven-Chan commented Apr 11, 2017

Skygear Server Date/Version: v0.22.1, python plugin with zmq

Steps to reproduce

  1. client call save record
  2. trigger after_save in plugin
  3. client call http handler or lambda
  4. the handler function is not called
  5. plugin time out after a while

Methods to make the handler work:
either:

  • use http instead of zmq
  • set async=False
@Steven-Chan Steven-Chan changed the title HTTP handler or Lambda not getting called, after triggering after_save with async=True Plugin HTTP handler or Lambda not getting called, after triggering after_save with async=True Apr 11, 2017
@Steven-Chan
Copy link
Contributor Author

Steven-Chan commented Apr 11, 2017

plugin:

import logging
import skygear

log = logging.getLogger(__name__)


@skygear.handler('handler', method=['POST'])
def handler(req):
    return {
        'result': 'handler is OK'
    }


@skygear.after_save('recordA', async=True)
def recordA_async_after_save(record, original_record, conn):
    log.info('recordA_async_after_save')

client.js

const skygear = require('skygear');
const agent = require('superagent');

const RecordA = skygear.Record.extend('recordA');

skygear.config({
  'apiKey': 'apikey',
  'endPoint': 'http://localhost:3000/',
}).then(() => {
  return skygear.signupAnonymously();
}).then(() => {
  const r = new RecordA({ 'content': 'Hello World' });
  return skygear.publicDB.save(r, {atomic: true});
}).then(() => {
  console.log('save success');
  agent.post('http://localhost:3000/handler').end((err, res) => {
    if (err) {
      console.log('http handler err');
    } else {
      console.log('http handler success');
    }
  });
}).catch(() => {
  console.log('save failed');
});

log:

save success

## after a while
http handler err

@b123400
Copy link
Contributor

b123400 commented Apr 12, 2017

Cause identified.

ZMQ broker expect the response channel to be consumed.
zmqTransport does not always consume response channel.

When a request is ended before async handler responds, transport gives up consuming from broker. Broker keeps waiting for the channel to be consumed.

Working on a fix.

@chpapa
Copy link
Contributor

chpapa commented Apr 24, 2017

@Steven-Chan Can you help verify the pull request fixed your issue? If yes please close it.

@rickmak
Copy link
Member

rickmak commented Apr 24, 2017

Steven verified it is fixed.

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

No branches or pull requests

4 participants