I would like somebody to consider Petr Jelineks patch for worker.c from here (/message-id/619c557d-93e6-1833-1692-b010b176ff77%402ndquadrant.com)
I'm was facing the same issue with 10.1 and BEFORE INSERT OR UPDATE triggers.
BRThomas Rosenstein